Skip to content

Commit d4bbe43

Browse files
agents sdk instructions
1 parent ecfa0f5 commit d4bbe43

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# Invariant SDK documentation
22

3-
Documentation for the Invariant SDK.
3+
Documentation for the Invariant SDK.
44

55
For the live version, please [visit](https://explorer.invariantlabs.ai/docs/).
66

77
To locally serve a live version of the documentation, run the following command in this directory:
88

99
```bash
10-
./dev serve
10+
./run up
1111
```
1212

1313
**Requirements:** Docker
14-
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# OpenAI Agents SDK
2+
3+
<div class='subtitle'>Use Gateway with the Agents SDK</div>
4+
5+
[OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) relies on OpenAI's Python client, which makes it very easy to integrate Gateway, similar to the standard [OpenAI integration](../llm-provider-integrations/openai.md).
6+
7+
## Getting the Invariant API Key
8+
9+
Visit the [Explorer Documentation](https://explorer.invariantlabs.ai/docs/explorer) to learn how to obtain your own API key.
10+
11+
## SDK Integration
12+
13+
You can then use Gateway with the Agents SDK by re-configuring the OpenAI client's base URL:
14+
15+
```python
16+
from agents import Agent, OpenAIChatCompletionsModel, Runner, function_tool
17+
from openai import AsyncOpenAI
18+
import os
19+
20+
external_client = AsyncOpenAI(
21+
base_url="https://explorer.invariantlabs.ai/api/v1/gateway/weather-agent/openai",
22+
default_headers={
23+
"Invariant-Authorization": "Bearer " + os.getenv("INVARIANT_API_KEY"),
24+
},
25+
)
26+
27+
28+
@function_tool
29+
async def fetch_weather(location: str) -> str:
30+
return "sunny"
31+
32+
33+
agent = Agent(
34+
name="Assistant",
35+
instructions="You are a helpful assistant",
36+
model=OpenAIChatCompletionsModel(
37+
model="gpt-4o",
38+
openai_client=external_client,
39+
),
40+
tools=[fetch_weather],
41+
)
42+
43+
result = Runner.run_sync(
44+
agent,
45+
"What is the weather like in Paris?",
46+
)
47+
print(result.final_output)
48+
49+
```
50+
51+
This will automatically trace your agent interactions in Invariant Explorer.
52+
53+
## Explore Other Integrations
54+
55+
<div class='tiles'>
56+
57+
<a href="../microsoft-autogen" class='tile'>
58+
<span class='tile-title'>Microsoft AutoGen Integration →</span>
59+
<span class='tile-description'>Enhance and debug your Microsoft AutoGen agents effortlessly using the Gateway.</span>
60+
</a>
61+
62+
<a href="../openhands" class='tile'>
63+
<span class='tile-title'>OpenHands Integration →</span>
64+
<span class='tile-description'>Streamline the development and debugging of OpenHands applications with the Gateway.</span>
65+
</a>
66+
67+
<a href="../swe-agent" class='tile'>
68+
<span class='tile-title'>SWE-agent Integration →</span>
69+
<span class='tile-description'>Streamline the development and debugging of SWE-agent applications with the Gateway.</span>
70+
</a>
71+
72+
<a href="../browser-use" class='tile'>
73+
<span class='tile-title'>Browser Use Integration →</span>
74+
<span class='tile-description'>Optimize and troubleshoot your Browser Use applications with Invariant Gateway.</span>
75+
</a>
76+
77+
</div>

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ nav:
7878
- Anthropic: gateway/llm-provider-integrations/anthropic.md
7979
- Agent Integrations:
8080
- Microsoft AutoGen: gateway/agent-integrations/microsoft-autogen.md
81+
- OpenAI Agents SDK: gateway/agent-integrations/openai-agents-sdk.md
8182
- OpenAI Swarm: gateway/agent-integrations/openai-swarm.md
8283
- OpenHands: gateway/agent-integrations/openhands.md
8384
- SWE Agent: gateway/agent-integrations/swe-agent.md

run

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python3
2-
# ./do build
2+
# ./run build
33
# docker build -t invariant-docs .
4-
# ./do serve
4+
# ./run serve
55
# docker build -t invariant-docs . && docker run -it -p 8000:8000 -e DEV_MODE=true -v .:/docs/ invariant-docs
66

77
import sys
@@ -29,5 +29,5 @@ elif sys.argv[1] == "up":
2929
webbrowser.open("http://localhost:8000")
3030
p.wait()
3131
else:
32-
print("Usage: ./dev build | ./dev up")
32+
print("Usage: ./run <build|up>")
3333
sys.exit(1)

0 commit comments

Comments
 (0)