-
Notifications
You must be signed in to change notification settings - Fork 780
Add OpenAI integration docs #4969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
03dd178
Add OpenAI integration docs
yaron2 9b11547
add openai link
yaron2 13527c0
Update daprdocs/content/en/developing-applications/openai-agents/_ind…
yaron2 a03f830
Update daprdocs/content/en/developing-applications/openai-agents/open…
yaron2 9127531
Update daprdocs/content/en/developing-applications/openai-agents/open…
yaron2 6cb1abd
Update daprdocs/content/en/developing-applications/openai-agents/open…
yaron2 22f96c1
Update daprdocs/content/en/developing-applications/openai-agents/open…
yaron2 94e1d9f
Merge branch 'v1.16' into openai-1
yaron2 a46676e
Merge branch 'v1.16' into openai-1
msfussell 28acb81
Update daprdocs/content/en/developing-applications/openai-agents/open…
yaron2 e86ee2e
address feedback, move to new AI structure
yaron2 eb8bf40
fix links
yaron2 d15370f
remove old content
yaron2 c4aea88
Update daprdocs/content/en/developing-ai/agent-integrations/_index.md
yaron2 a11bd21
Update daprdocs/content/en/developing-ai/agent-integrations/openai-ag…
yaron2 1f7b378
Update daprdocs/content/en/developing-ai/agent-integrations/_index.md
msfussell b34f56a
Update daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-why.md
msfussell 39acffc
Update daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-why.md
msfussell 5570bcd
Update daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-intr…
msfussell df5c3a5
Update daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-intr…
msfussell ccf612c
Update daprdocs/content/en/developing-ai/agent-integrations/_index.md
yaron2 bf37a2d
Update daprdocs/content/en/developing-ai/_index.md
yaron2 108d56c
Merge remote-tracking branch 'origin/v1.16' into openai-1
yaron2 1d17e76
change links
yaron2 594448f
fix ref
yaron2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| type: docs | ||
| title: "Developing AI with Dapr" | ||
| linkTitle: "Developing AI" | ||
| description: "Information on how to build reliable and secure agentic AI systems with Dapr" | ||
| weight: 31 | ||
| --- |
22 changes: 22 additions & 0 deletions
22
daprdocs/content/en/developing-ai/agent-integrations/_index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| type: docs | ||
| title: "Agent Integrations" | ||
| linkTitle: "Agent Integrations" | ||
| weight: 25 | ||
| description: "Information on how to integrate agentic frameworks with Dapr runtime" | ||
| --- | ||
|
|
||
| ### What are agent integrations in Dapr? | ||
|
|
||
| Dapr augments and enhances other agentic frameworks by providing them with key critical features for running in production: | ||
|
|
||
| * Durable execution using [Dapr Workflows]({{% ref workflow-overview %}}) for resilient and long-running AI tasks | ||
| * Portable agent context & memory using Dapr's [State Management API]({{% ref "state-management-overview" %}}) | ||
| * Reliable and secure agent-to-agent communication using [Dapr Pub/Sub]({{% ref "pubsub-overview" %}}) and [Service Invocation | ||
| ]({{% ref service-invocation-overview %}}) | ||
| * Secure agent [identity]({{< ref "concepts/security-concept" >}}#application-identity) | ||
|
|
||
| {{< button text="Install Dapr" page="getting-started.md" >}} | ||
|
|
||
| With Dapr, developers writing AI systems using the framework of their choice enjoy accelerated development via the Dapr APIs and gain confidence taking agentic systems into production. | ||
|
|
||
12 changes: 12 additions & 0 deletions
12
daprdocs/content/en/developing-ai/agent-integrations/openai-agents/_index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| type: docs | ||
| title: "OpenAI Agents" | ||
| linkTitle: "OpenAI Agents" | ||
| weight: 25 | ||
| description: "Dapr first-class integrations for OpenAI Agents" | ||
| --- | ||
|
|
||
| ### What is the Dapr OpenAI Agents integration? | ||
|
|
||
| Dapr provides OpenAI agents first class integrations that range from agent session management to connecting agents via pub/sub and orchestrating agentic workflows. The Dapr OpenAI integration is an extension in the OpenAI Python SDK that developers can use to augment OpenAI agents with the various Dapr APIs. | ||
|
|
127 changes: 127 additions & 0 deletions
127
...ent/en/developing-ai/agent-integrations/openai-agents/openai-agents-sessions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| --- | ||
| type: docs | ||
| title: "Agent Sessions" | ||
| linkTitle: "Agent Sessions" | ||
| weight: 20 | ||
| description: "How to use Dapr to reliably and securely manage agent state" | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| By using Dapr to manage the state and [session data for OpenAI agents](https://openai.github.io/openai-agents-python/sessions/), users can store agent state in all databases supported by Dapr, including key/value stores, caches and SQL databases. Developers also get built-in tracing, metrics and resiliency policies that make agent session data operate reliably in production. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| Initialize Dapr locally to set up a self-hosted environment for development. This process fetches and installs the Dapr sidecar binaries, runs essential services as Docker containers, and prepares a default components folder for your application. For detailed steps, see the official [guide on initializing Dapr locally]({{% ref install-dapr-cli.md %}}). | ||
|
|
||
| To initialize the Dapr control plane containers and create a default configuration file, run: | ||
|
|
||
| ```bash | ||
| dapr init | ||
| ``` | ||
|
|
||
| Verify you have container instances with `daprio/dapr`, `openzipkin/zipkin`, and `redis` images running: | ||
|
|
||
| ```bash | ||
| docker ps | ||
| ``` | ||
|
|
||
| ### Install Python | ||
|
|
||
| {{% alert title="Note" color="info" %}} | ||
| Make sure you have Python already installed. `Python >=3.10`. For installation instructions, visit the official [Python installation guide](https://www.python.org/downloads/). | ||
| {{% /alert %}} | ||
|
|
||
| ### Install Dependencies | ||
|
|
||
| ```bash | ||
| pip install openai-agents dapr | ||
| ``` | ||
|
|
||
| ### Create an OpenAI Agent | ||
|
|
||
| Let's create a simple OpenAI agent. Put the following in a file named `openai_agent.py`: | ||
|
|
||
| ```python | ||
| import asyncio | ||
| from agents import Agent, Runner | ||
| from agents.extensions.memory.dapr_session import DaprSession | ||
|
|
||
| async def main(): | ||
| agent = Agent( | ||
| name="Assistant", | ||
| instructions="Reply very concisely.", | ||
| ) | ||
|
|
||
| session = DaprSession.from_address( | ||
| session_id="123", | ||
| state_store_name="statestore" | ||
| ) | ||
|
|
||
| result = await Runner.run(agent, "What city is the Golden Gate Bridge in?", session=session) | ||
| print(result.final_output) | ||
|
|
||
| result = await Runner.run(agent, "What state is it in?", session=session) | ||
| print(result.final_output) | ||
|
|
||
| result = await Runner.run(agent, "What's the population?", session=session) | ||
| print(result.final_output) | ||
|
|
||
| asyncio.run(main()) | ||
| ``` | ||
|
|
||
| ### Set an OpenAI API key | ||
|
|
||
| ```bash | ||
| export OPENAI_API_KEY=sk-... | ||
| ``` | ||
|
|
||
| ### Create a Python venv | ||
|
|
||
| ```bash | ||
| python -m venv .venv | ||
| source .venv/bin/activate # On Windows: .venv\Scripts\activate | ||
| ``` | ||
|
|
||
| ### Create the database component | ||
|
|
||
| The component file is how Dapr connects to your databae. The full list of supported databases can be found [here]({{% ref supported-state-stores %}}). Create a `components` directory and this file in it: | ||
|
|
||
| `statestore.yaml`: | ||
|
|
||
| ```yaml | ||
| apiVersion: dapr.io/v1alpha1 | ||
| kind: Component | ||
| metadata: | ||
| name: statestore | ||
| spec: | ||
| type: state.redis | ||
| version: v1 | ||
| metadata: | ||
| - name: redisHost | ||
| value: localhost:6379 | ||
| - name: redisPassword | ||
| value: "" | ||
| ``` | ||
|
|
||
| ### Run The Agent | ||
|
|
||
| Now run the local Dapr process and your Python script using the Dapr CLI. | ||
|
|
||
| ```bash | ||
| dapr run --app-id openaisessions --dapr-grpc-port 50001 --resources-path ./components -- python3 ./openai_agent.py | ||
| ``` | ||
|
|
||
| Open `http://localhost:9411` to view your the traces and dependency graph. | ||
|
|
||
| You can see [the session data stored in Redis]({{% ref "getting-started/get-started-api" %}}#step-4-see-how-the-state-is-stored-in-redis) with the following command | ||
|
|
||
| ```bash | ||
| hgetall "123:messages" | ||
| ``` | ||
|
|
||
| ## Next Steps | ||
|
|
||
| Now that you have an OpenAI agent using Dapr to manage the agent sessions, explore more you can do with the [State API]({{% ref "state-management-overview" %}}) and how to enable [resiliency policies]({{% ref resiliency-overview %}}) for enhanced reliability. | ||
|
|
||
| Read more about OpenAI agent sessions and Dapr [here](https://openai.github.io/openai-agents-python/sessions/). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.