Skip to main content

Overview

The Decision Service uses AI to analyze a decision scenario with multiple options and returns the best choice along with reasoning. It’s ideal for:
  • Condition assessment (Excellent, Good, Fair, Poor)
  • Category classification
  • Policy decisions
  • Any scenario requiring selection from predefined options

Simple & Fast

Single-purpose service with quick responses.

Context-Aware

Uses item context and business context for informed decisions.

Structured Output

Returns selected option and reasoning explanation.

No Conversation

Direct decision without conversational flow.

How It Works

Request → Decision Agent → LLM Analysis → Structured Output → Response
The agent:
  1. Receives prompt, options, and context
  2. Analyzes the scenario using AI
  3. Selects one option from the provided list
  4. Returns decision with reasoning

API Endpoint

POST /loopos_ai_decision

Request Example

{
  "language": "PT-PT",
  "prompt": "What condition best describes this item?",
  "options": ["Excellent", "Good", "Fair", "Poor"],
  "item_context": "iPhone 12 with minor scratches on the screen",
  "context": "Assessing item condition for marketplace listing"
}

Response Example

{
  "decision": "Good",
  "reasoning": "Based on the description of minor scratches on the screen, the item is in good condition. While not excellent due to visible wear, it shows only light damage and remains fully functional."
}

Request Parameters

FieldTypeRequiredDescription
languagestringNoLanguage code (default: “PT-PT”)
promptstringYesThe question/decision prompt
optionsarray or stringYesList of options (can be comma-separated string)
item_contextstringYesContext about the item
contextstringNoAdditional business/user context
loopos_core_contextstringNoBusiness context for the AI agent
session_extra_dataobjectNoAdditional session metadata

Response Fields

FieldTypeDescription
decisionstringThe selected option (guaranteed to be one of the provided options)
reasoningstringExplanation of why this decision was made

Use Cases

Condition Assessment

{
  "prompt": "What condition best describes this item?",
  "options": ["A - Excellent", "B - Good", "C - Fair", "D - Poor"],
  "item_context": "iPhone 12 with minor scratches, fully functional"
}

Category Classification

{
  "prompt": "What category does this item belong to?",
  "options": ["Electronics", "Furniture", "Clothing", "Books"],
  "item_context": "Used iPhone 12 in good condition"
}

Policy Decisions

{
  "prompt": "Should this item be accepted for online sale?",
  "options": ["Yes", "No", "Requires Review"],
  "item_context": "Item description and condition",
  "context": "Policy: Items in condition C or D require review"
}

Best Practices

Be specific with prompts: Clear, specific prompts lead to better decisions.
Provide context: Include relevant item context and business context for informed decisions.
Limit options: Keep options list manageable (typically 2-10 options work best).
Use consistent options: Use the same option format across related decisions for consistency.

Options Format

Options can be provided as: Array format (recommended):
{
  "options": ["Excellent", "Good", "Fair", "Poor"]
}
Comma-separated string:
{
  "options": "Excellent, Good, Fair, Poor"
}

Error Handling

The service returns standard HTTP status codes:
  • 200 OK: Decision made successfully
  • 422 Validation Error: Missing required fields or invalid input
  • 500 Internal Server Error: Server-side error
Example error response:
{
  "detail": [
    {
      "loc": ["body", "prompt"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}

Performance

The Decision Service is optimized for speed:
  • Average latency: ~2-3 seconds
  • Model: Uses fast models (e.g., Gemini 2.0 Flash, gpt-4o-mini)
  • Cost: Low cost per request (~$0.00003-0.0001)