Skip to main content

LlamaIndex Agent Server Adapter

PyPI version Python 3.10+ License: MIT

An adapter for hosting LlamaIndex Workflows as Azure AI Agent Server endpoints.

Installation

pip install llamaindex-agentserver-adapter

With OpenAI support:

pip install llamaindex-agentserver-adapter[openai]

With Azure OpenAI support:

pip install llamaindex-agentserver-adapter[azure-openai]

Quick Start

from workflows import Workflow, step
from workflows.events import StartEvent, StopEvent
from llamaindex_agentserver import from_workflow


class MyWorkflow(Workflow):
    @step
    async def process(self, ev: StartEvent) -> StopEvent:
        user_input = ev.input
        return StopEvent(result=f"Processed: {user_input}")


# Create and run the adapter
workflow = MyWorkflow(timeout=60)
adapter = from_workflow(workflow)
adapter.run(port=8088)

Features

  • HTTP Endpoints: Exposes your workflow via /runs and /responses endpoints
  • Streaming Support: Full support for streaming responses using Server-Sent Events
  • Human-in-the-Loop: Support for InputRequiredEvent and HumanResponseEvent patterns
  • Tracing: Integration with Azure Application Insights and OpenTelemetry
  • Health Checks: Built-in /liveness and /readiness endpoints

API Reference

from_workflow(workflow, state_converter=None, timeout=None)

Creates an adapter for a LlamaIndex Workflow.

Parameters:

  • workflow: The LlamaIndex Workflow instance to adapt
  • state_converter: Optional custom state converter for non-standard input/output formats
  • timeout: Optional timeout override for workflow execution

Returns: A LlamaIndexWorkflowAdapter instance

Request Format

The adapter accepts requests in the OpenAI Responses API format:

{
  "input": "Hello, world!",
  "instructions": "You are a helpful assistant.",
  "stream": false,
  "metadata": {}
}

Or with structured messages:

{
  "input": [
    {"type": "message", "role": "user", "content": "Hello!"},
    {"type": "message", "role": "assistant", "content": "Hi there!"},
    {"type": "message", "role": "user", "content": "How are you?"}
  ],
  "stream": true
}

Testing Your Server

# Non-streaming request
curl -X POST http://localhost:8088/runs \
  -H "Content-Type: application/json" \
  -d '{"input": "Hello, how are you?"}'

# Streaming request
curl -X POST http://localhost:8088/runs \
  -H "Content-Type: application/json" \
  -d '{"input": "Tell me a story", "stream": true}'

# Health check
curl http://localhost:8088/liveness

Custom State Converter

For workflows with custom input/output requirements, implement a custom state converter:

from llamaindex_agentserver.models import LlamaIndexWorkflowStateConverter


class MyStateConverter(LlamaIndexWorkflowStateConverter):
    def supports_streaming(self, context):
        return True

    def request_to_workflow_input(self, context):
        # Convert request to your workflow's expected input format
        return {"custom_input": context.request.get("input")}

    def result_to_response(self, result, context):
        # Convert workflow result to Response object
        ...

    async def stream_to_response_stream(self, event_stream, context):
        # Convert streaming events to response stream events
        ...


adapter = from_workflow(workflow, state_converter=MyStateConverter())

Environment Variables

Variable Description
DEFAULT_AD_PORT Default server port (default: 8088)
_AGENT_RUNTIME_APP_INSIGHTS_CONNECTION_STRING Application Insights connection string
OTEL_EXPORTER_ENDPOINT OpenTelemetry exporter endpoint
AGENT_DEBUG_ERRORS Set to "true" to include full error details
AGENT_LOG_LEVEL Logging level (default: INFO)

Examples

See the examples/ directory:

Requirements

  • Python 3.10+
  • azure-ai-agentserver-core (Azure AI Agent Server core library)
  • llama-index-core and llama-index-workflows

Development

# Clone the repository
git clone https://github.com/yourusername/llamaindex-agentserver-adapter.git
cd llamaindex-agentserver-adapter

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
ruff format .

# Lint
ruff check .

License

MIT License - See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llamaindex_agentserver_adapter-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llamaindex_agentserver_adapter-0.1.0.tar.gz.

File metadata

File hashes

Hashes for llamaindex_agentserver_adapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 90fcebf854b153a89c2da8ff187e1749400bc7daff641c6dc95f5f64beffdaab
MD5 44c5f9f7c17ce8e4273e5bc9beb0be88
BLAKE2b-256 1f02f8dd8088283ab6ebd23e8f77b88a65c2095032b763fb16dd6d33917f9219

See more details on using hashes here.

File details

Details for the file llamaindex_agentserver_adapter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llamaindex_agentserver_adapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed0842a60230c7fd5c8a1e2fdbc763cf3e83ea18127dde16a8a542d612648a4a
MD5 6892508fbc44f68c5d2133ac2f7898c2
BLAKE2b-256 c774e71053ea869ec5c72e489ddcee96d950b37e5c180419c5ae786a2bdfdc87

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page