From 47570a8c5d81e97e8adf5369c9c8cefaea050e52 Mon Sep 17 00:00:00 2001 From: Luca Beurer-Kellner Date: Wed, 5 Mar 2025 14:46:54 +0100 Subject: [PATCH] update readme --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ examples/swarm_agent.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 examples/swarm_agent.py diff --git a/README.md b/README.md index 4a44343..8d02584 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,45 @@ To add Gateway to your agentic system, simply follow the integration guides belo > **Note:** Do not include the curly braces `{}`. If the dataset does not exist in Invariant Explorer, it will be created before adding traces. +### **🔹 OpenAI Swarm Integration** + +Integrating directly with a specific agent framework is also supported, simply by configuring the underlying LLM client. + +For instance, [OpenAI Swarm](https://github.com/openai/swarm) relies on OpenAI's Python client, the setup is very similar to the standard OpenAI integration: + +```python +from swarm import Swarm, Agent +from openai import OpenAI +from httpx import Client +import os + +client = Swarm( + client=OpenAI( + http_client=Client(headers={"Invariant-Authorization": "Bearer " + os.getenv("INVARIANT_API_KEY", "")}), + base_url="https://explorer.invariantlabs.ai/api/v1/proxy/weather-swarm-agent/openai", + ) +) + + +def get_weather(): + return "It's sunny." + + +agent = Agent( + name="Agent A", + instructions="You are a helpful agent.", + functions=[get_weather], +) + +response = client.run( + agent=agent, + messages=[{"role": "user", "content": "What's the weather?"}], +) + +print(response.messages[-1]["content"]) +# Output: "It seems to be sunny." +``` + --- ## Quickstart for Users diff --git a/examples/swarm_agent.py b/examples/swarm_agent.py new file mode 100644 index 0000000..ecf2f28 --- /dev/null +++ b/examples/swarm_agent.py @@ -0,0 +1,34 @@ +from swarm import Swarm, Agent +from openai import OpenAI +from httpx import Client +import os + +client = Swarm( + client=OpenAI( + http_client=Client( + headers={ + "Invariant-Authorization": "Bearer " + + os.getenv("INVARIANT_API_KEY", "") + } + ), + base_url="https://explorer.invariantlabs.ai/api/v1/proxy/weather-swarm-agent/openai", + ) +) + + +def get_weather(): + return "It's sunny." + + +agent = Agent( + name="Agent A", + instructions="You are a helpful agent.", + functions=[get_weather], +) + +response = client.run( + agent=agent, + messages=[{"role": "user", "content": "What's the weather?"}], +) + +print(response.messages[-1]["content"])