File tree Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 390
390
"group" : " Libraries" ,
391
391
"pages" : [
392
392
" integrations/libraries" ,
393
+ " integrations/libraries/openai-agents" ,
393
394
" integrations/libraries/autogen" ,
394
395
" integrations/libraries/dspy" ,
395
396
" integrations/libraries/instructor" ,
409
410
},
410
411
{
411
412
"group" : " Tracing Providers" ,
412
- "pages" : [" integrations/tracing-providers/arize" ]
413
+ "pages" : [
414
+ " integrations/tracing-providers/arize" ,
415
+ " integrations/tracing-providers/logfire"
416
+ ]
413
417
}
414
418
]
415
419
},
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : " OpenAI Agents"
3
+ description : " OpenAI Agents are a powerful tool for building and deploying agents that can be used to automate tasks and workflows."
4
+ ---
5
+
6
+ ## Tracing OpenAI Agents
7
+
8
+ Portkey provides an opentelemetry compatible backend to store and query your traces.
9
+
10
+ You can trace your OpenAI Agents using any OpenTelemetry compatible tracing library.
11
+
12
+ Here is an example of how to trace your OpenAI Agents using the [ ` logfire ` ] ( /integrations/tracing/logfire ) library from Pydantic:
13
+
14
+ ``` python Python
15
+ import logfire
16
+ from pydantic import BaseModel
17
+ from agents import Agent, Runner, function_tool
18
+ import asyncio
19
+ import os
20
+
21
+ os.environ[" OTEL_EXPORTER_OTLP_ENDPOINT" ] = " https://api.portkeydev.com/v1/logs/otel"
22
+ os.environ[" OTEL_EXPORTER_OTLP_HEADERS" ] = f " x-portkey-api-key= { YOUR_PORTKEY_API_KEY } "
23
+
24
+ class Weather (BaseModel ):
25
+ city: str
26
+ temperature_range: str
27
+ conditions: str
28
+
29
+ @function_tool
30
+ def get_weather (city : str ) -> Weather:
31
+ return Weather(city = city, temperature_range = " 14-20C" , conditions = " Sunny with wind." )
32
+
33
+ agent = Agent(
34
+ name = " Hello world" ,
35
+ instructions = " You are a helpful agent." ,
36
+ tools = [get_weather]
37
+ )
38
+
39
+ async def main ():
40
+ logfire.configure(
41
+ service_name = ' my_agent_service' ,
42
+ send_to_logfire = False ,
43
+ )
44
+ logfire.instrument_openai_agents()
45
+ result = await Runner.run(agent, input = " What's the weather in Tokyo?" )
46
+ print (result.final_output)
47
+
48
+ if __name__ == " __main__" :
49
+ asyncio.run(main())
50
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : " Pydantic Logfire"
3
+ description : " Logfire is a tool for comprehensive observability of your LLM applications with OpenTelemetry."
4
+ ---
5
+
6
+
7
+ [ Logfire] ( https://pydantic.dev/logfire ) and any opentelemetry compatible tracing library works out of the box with Portkey.
8
+
9
+ All you need to do is set the following environment variables in your application:
10
+
11
+ ``` sh
12
+ OTEL_EXPORTER_OTLP_ENDPOINT = " https://api.portkeydev.com/v1/logs/otel"
13
+ OTEL_EXPORTER_OTLP_HEADERS = " x-portkey-api-key={YOUR_PORTKEY_API_KEY}"
14
+ ```
15
+
16
+
17
+
You can’t perform that action at this time.
0 commit comments