For the complete documentation index, see llms.txt. This page is also available as Markdown.

Common Patterns

Production-ready Classic API patterns for conversation lifecycle, user models, webhooks, routing, and CI simulation gates.

Production-ready patterns for building with the Amigo AI API. Each pattern includes runnable Python and TypeScript examples.

Classic API. These patterns use the Classic API SDKs and endpoints at api.amigo.ai. For Platform API equivalents, start with the Platform SDK Quickstart.

1. Conversation Lifecycle Management

Create a conversation, send messages, handle streaming events, and finish cleanly.

from amigo_sdk import AsyncAmigoClient
from amigo_sdk.models import (
    ConversationCreateConversationRequest,
    CreateConversationParametersQuery,
    InteractWithConversationParametersQuery,
    Format,
)

async def run_conversation():
    async with AsyncAmigoClient() as client:
        # 1. Create conversation (service_id goes in the request body)
        params = CreateConversationParametersQuery(
            response_format="text",
        )
        body = ConversationCreateConversationRequest(service_id="your-service-id")

        conversation_id = None
        async for event in await client.conversations.create_conversation(body, params):
            if hasattr(event, "conversation_id"):
                conversation_id = event.conversation_id
            # Handle greeting events...

        # 2. Interact
        interact_params = InteractWithConversationParametersQuery(
            request_format=Format.text,
            response_format="text",
        )
        async for event in await client.conversations.interact_with_conversation(
            conversation_id,
            interact_params,
            text_message="Hello, I need help with my account",
        ):
            print(event)

        # 3. Finish
        await client.conversations.finish_conversation(conversation_id)

Key considerations:

  • Always call finish_conversation when done to release server resources.

  • Handle the NDJSON stream event by event. Don't buffer the entire response.

  • Use abort_event (Python) or AbortController (TypeScript) for cancellation.


2. User Creation and User Model Queries

Create users, let conversations enrich the user model, and query the result. To push facts from your own systems into the model, use additional_context - see Enriching the User Model.


3. Webhook-Driven Memory Sync

Receive conversation events via webhooks and sync memories to an external system.

Key considerations:

  • Always use constant-time comparison for signature verification.

  • Respond with 200 quickly and process events asynchronously if needed.

  • Implement idempotency using the x-amigo-idempotent-key header, which stays constant across retries.

  • Event payload shapes are documented in Webhook Event Types.


4. Multi-Service Routing

List available services and route conversations to the appropriate one based on user needs.


5. Simulation-Driven Deployment

Run automated simulations before deploying agent changes to production. Unlike the patterns above, this one uses the Agent Forge CLI (forge) rather than the SDKs - the CLI wraps the simulation APIs and is the recommended way to gate deployments in CI.

Key considerations:

  • Use --test-user for parallel simulation execution without conflicts.

  • Set --analyze-wait to allow time for metrics computation after simulation.

  • Define clear pass/fail thresholds for your metrics (for example, safety >= 9.0).

Last updated

Was this helpful?