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.

Metadata

Release files for llamaindex-agentserver-adapter 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llamaindex-agentserver-adapter 0.1.0
File Size Uploaded
llamaindex_agentserver_adapter-0.1.0.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llamaindex-agentserver-adapter 0.1.0
File Interpreter ABI Platform
llamaindex_agentserver_adapter-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.1 kB

Release files / llamaindex_agentserver_adapter-0.1.0.tar.gz

Download URL llamaindex_agentserver_adapter-0.1.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
90fcebf854b153a89c2da8ff187e1749400bc7daff641c6dc95f5f64beffdaab
BLAKE2b-256 checksum
How to use checksums
1f02f8dd8088283ab6ebd23e8f77b88a65c2095032b763fb16dd6d33917f9219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / llamaindex_agentserver_adapter-0.1.0-py3-none-any.whl

Download URL llamaindex_agentserver_adapter-0.1.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed0842a60230c7fd5c8a1e2fdbc763cf3e83ea18127dde16a8a542d612648a4a
BLAKE2b-256 checksum
How to use checksums
c774e71053ea869ec5c72e489ddcee96d950b37e5c180419c5ae786a2bdfdc87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page