Multi-agents
Purpose
Section titled “Purpose”This mode is used in applications implementing multi-agent architectures where models may:
- plan multi-step reasoning,
- invoke tools,
- exchange context,
- generate final responses.
Architectural Principle
Section titled “Architectural Principle”Responsibility separation:
- LLM calls go through the Gateway
- Tools execute locally in your application
- HiveTrace analyzes only LLM requests and responses
Gateway does not execute tools and does not orchestrate agents.
What Changes When Switching from OpenAI to Gateway
Section titled “What Changes When Switching from OpenAI to Gateway”Endpoint
Section titled “Endpoint”Before:
base_url="https://api.openai.com/v1"With Gateway:
base_url=$GATEWAY_URL # e.g. http://host:4100/v1Must point strictly to /v1.
API Key
Section titled “API Key”Before:
api_key=$OPENAI_API_KEYWith Gateway:
api_key=$LITELLM_MASTER_KEYRequired Headers for HiveTrace
Section titled “Required Headers for HiveTrace”X-Application-Id: <HIVETRACE_APPLICATION_ID>X-User-Id: <USER_ID>X-Session-Id: <SESSION_ID>Optional:
X-HiveTrace-Mode: sync | asyncX-HiveTrace-Skip-System-Requests: falseFor multi-agent systems, typically:
X-HiveTrace-Skip-System-Requests: falseto preserve system instructions for audit.
Telemetry Behavior
Section titled “Telemetry Behavior”Agents may perform multiple LLM calls per user request:
- planning
- tool calls
- continuation
- final response
Gateway configuration:
HIVETRACE_DEDUP_AGENT_TOOL_CALLS=trueHIVETRACE_SKIP_SYSTEM_REQUESTS=falsePrevents duplicate user input records and preserves system context.
Tools:
- execute locally
- are not proxied through Gateway
- are invisible to HiveTrace except through LLM I/O
Minimal Example
Section titled “Minimal Example”import osimport httpxfrom openai import AsyncOpenAIfrom agents import Agent, Runner, function_toolfrom agents.models.openai_chatcompletions import OpenAIChatCompletionsModel
@function_tooldef fetch_users_summary(): return {"total": 123}
openai_client = AsyncOpenAI( base_url=os.environ["GATEWAY_URL"], api_key=os.environ["LITELLM_MASTER_KEY"], default_headers={ "X-Application-Id": os.environ["HIVETRACE_APPLICATION_ID"], "X-User-Id": os.environ["USER_ID"], "X-Session-Id": os.environ["SESSION_ID"], },)
model = OpenAIChatCompletionsModel( model="gpt-4.1-mini", openai_client=openai_client)
agent = Agent( name="Assistant", instructions="Call fetch_users_summary then respond.", tools=[fetch_users_summary], model=model,)
result = await Runner.run(agent, input=[{"role": "user", "content": "How many users?"}])print(result.final_output)Summary
Section titled “Summary”To enable multi-agents with Gateway:
- Change
base_url - Use
LITELLM_MASTER_KEY - Add HiveTrace headers
- Configure Gateway telemetry env variables
Agent runtime and tool logic remain unchanged.