You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initialize AgentOps at the beginning of your application. It will automatically instrument the OpenAI Agents SDK. The "Hello World Example" below demonstrates basic usage.
62
+
AgentOps will automatically instrument the OpenAI Agents SDK after being initialized. You can then create agents, run them, and track their interactions.
63
63
64
-
<CodeGroup>
65
-
```python Hello World Example
66
-
from agents import Agent, Runner
64
+
```python
67
65
import agentops
68
-
import os # Ensure os is imported if using os.getenv
69
-
70
-
# Initialize AgentOps.
71
-
# If AGENTOPS_API_KEY is in env, it's used. Otherwise, pass it directly.
72
-
# Example: agentops.init(os.getenv("AGENTOPS_API_KEY")) or agentops.init("<YOUR_AGENTOPS_API_KEY>")
73
-
agentops.init() # Assumes AGENTOPS_API_KEY is in environment
66
+
from agents import Agent, Runner
74
67
75
-
# OpenAI client used by Agents SDK will pick up OPENAI_API_KEY from env.
68
+
# Initialize AgentOps
69
+
agentops.init()
76
70
71
+
# Create an agent with instructions
77
72
agent = Agent(name="Assistant", instructions="You are a helpful assistant")
78
73
79
74
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
80
75
print(result.final_output)
81
-
82
-
# Expected Output:
83
-
# Code within the code,
84
-
# Functions calling themselves,
85
-
# Infinite loop's dance.
86
76
```
87
-
</CodeGroup>
88
-
89
-
## Advanced Examples
90
77
91
-
### Handoffs Example
78
+
##Examples
92
79
93
-
```python
80
+
<CodeGroup>
81
+
```python Handoffs
94
82
from agents import Agent, Runner
95
83
import asyncio
96
84
import agentops
97
85
import os
98
86
99
-
agentops.init()# Assumes AGENTOPS_API_KEY is in environment
87
+
agentops.init()
100
88
101
89
spanish_agent = Agent(
102
90
name="Spanish agent",
@@ -125,15 +113,13 @@ if __name__ == "__main__":
125
113
asyncio.run(main())
126
114
```
127
115
128
-
### Functions Example
129
-
130
-
```python
116
+
```python Function Calling
131
117
import asyncio
132
118
from agents import Agent, Runner, function_tool
133
119
import agentops
134
120
import os
135
121
136
-
agentops.init()# Assumes AGENTOPS_API_KEY is in environment
122
+
agentops.init()
137
123
138
124
@function_tool
139
125
defget_weather(city: str) -> str:
@@ -156,27 +142,9 @@ async def main():
156
142
if__name__=="__main__":
157
143
asyncio.run(main())
158
144
```
145
+
</CodeGroup>
159
146
160
-
## The Agent Loop
161
-
162
-
When you call `Runner.run()`, the SDK runs a loop until it gets a final output:
163
-
164
-
1. The LLM is called using the model and settings on the agent, along with the message history.
165
-
2. The LLM returns a response, which may include tool calls.
166
-
3. If the response has a final output, the loop ends and returns it.
167
-
4. If the response has a handoff, the agent is set to the new agent and the loop continues from step 1.
168
-
5. Tool calls are processed (if any) and tool response messages are appended. Then the loop continues from step 1.
169
-
170
-
You can use the `max_turns` parameter to limit the number of loop executions.
171
-
172
-
## Final Output
173
-
174
-
Final output is the last thing the agent produces in the loop:
175
-
176
-
- If you set an `output_type` on the agent, the final output is when the LLM returns something of that type using structured outputs.
177
-
- If there's no `output_type` (i.e., plain text responses), then the first LLM response without any tool calls or handoffs is considered the final output.
178
-
179
-
## Examples
147
+
## More Examples
180
148
<CardGroupcols={2}>
181
149
<Cardtitle="Customer Service Agent"icon="notebook"href="/v2/examples/openai_agents">
<Cardtitle="Tool Use (Alternative)"icon="notebook"href="https://github.com/AgentOps-AI/agentops/blob/main/examples/anthropic/anthropic-example-tool.ipynb"newTab={true}>
246
-
Another example of tool usage with Anthropic models.
0 commit comments