Build multi-agent workflows with the OpenAI Agents SDK and Keywords AI.
KeywordsProcessor
pip install openai-agents
pip install keywordsai-tracing
pip install "keywordsai-tracing[openai-agents]"
https://api.keywordsai.co/api/openai/v1/traces/ingest
import asyncio import os from agents import Agent, Runner from agents.tracing import set_trace_processors from keywordsai_tracing.integrations.openai_agents_integration import KeywordsAITraceProcessor set_trace_processors( [ KeywordsAITraceProcessor( api_key=os.getenv("KEYWORDSAI_API_KEY"), endpoint="https://api.keywordsai.co/api/openai/v1/traces/ingest" ), ] ) async def main(): agent = Agent( name="Assistant", instructions="You only respond in haikus.", ) result = await Runner.run(agent, "Tell me about recursion in programming.") print(result.final_output) # Function calls itself, # Looping in smaller pieces, # Endless by design. if __name__ == "__main__": asyncio.run(main())
from agents import Agent, Runner import asyncio from keywordsai_tracing.integrations.openai_agents_integration import KeywordsAITraceProcessor from agents.tracing import set_trace_processors import os set_trace_processors( [ KeywordsAITraceProcessor( api_key=os.getenv("KEYWORDSAI_API_KEY"), endpoint="https://api.keywordsai.co/api/openai/v1/traces/ingest", ), ] ) spanish_agent = Agent( name="Spanish agent", instructions="You only speak Spanish.", ) english_agent = Agent( name="English agent", instructions="You only speak English", ) triage_agent = Agent( name="Triage agent", instructions="Handoff to the appropriate agent based on the language of the request.", handoffs=[spanish_agent, english_agent], ) async def main(): result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?") print(result.final_output) # ¡Hola! Estoy bien, gracias por preguntar. ¿Y tú, cómo estás? if __name__ == "__main__": asyncio.run(main())
import asyncio from agents import Agent, Runner, function_tool from keywordsai_tracing.integrations.openai_agents_integration import KeywordsAITraceProcessor from agents.tracing import set_trace_processors import os set_trace_processors( [ KeywordsAITraceProcessor( os.getenv("KEYWORDSAI_API_KEY"), endpoint="https://api.keywordsai.co/api/openai/v1/traces/ingest", ), ] ) @function_tool def get_weather(city: str) -> str: return f"The weather in {city} is sunny." agent = Agent( name="Hello world", instructions="You are a helpful agent.", tools=[get_weather], ) async def main(): result = await Runner.run(agent, input="What's the weather in Tokyo?") print(result.final_output) # The weather in Tokyo is sunny. if __name__ == "__main__": asyncio.run(main())
Was this page helpful?