-
Notifications
You must be signed in to change notification settings - Fork 79
OpenAI Agents agent pattern examples #224
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b4d763b
update for plugins
jssmith ef7a00d
formatting
jssmith 38375ca
reference main branch
jssmith 92286fd
cleanup
jssmith 1b6b026
switch to plugins on the runners
jssmith c157941
move around samples
jssmith 815c14b
update README files
jssmith 6c9213f
formatting update
jssmith 923a919
formatting
jssmith 396fb5c
timeout adjustments
jssmith 043e94b
porting agent patterns from OpenAI agents examples
jssmith 7a55523
Merge remote-tracking branch 'origin/main' into jssmith/openai-agent-…
tconley1428 fbe71a6
Revert uv.lock
tconley1428 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
31 changes: 31 additions & 0 deletions
31
openai_agents/agent_patterns/run_deterministic_workflow.py
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,31 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.deterministic_workflow import ( | ||
DeterministicWorkflow, | ||
) | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute a workflow | ||
result = await client.execute_workflow( | ||
DeterministicWorkflow.run, | ||
"Write a science fiction story about time travel", | ||
id="deterministic-workflow-example", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
50 changes: 50 additions & 0 deletions
50
openai_agents/agent_patterns/run_forcing_tool_use_workflow.py
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,50 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.forcing_tool_use_workflow import ( | ||
ForcingToolUseWorkflow, | ||
) | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute workflows with different tool use behaviors | ||
print("Testing default behavior:") | ||
result1 = await client.execute_workflow( | ||
ForcingToolUseWorkflow.run, | ||
"default", | ||
id="forcing-tool-use-workflow-default", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Default result: {result1}") | ||
|
||
print("\nTesting first_tool behavior:") | ||
result2 = await client.execute_workflow( | ||
ForcingToolUseWorkflow.run, | ||
"first_tool", | ||
id="forcing-tool-use-workflow-first-tool", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"First tool result: {result2}") | ||
|
||
print("\nTesting custom behavior:") | ||
result3 = await client.execute_workflow( | ||
ForcingToolUseWorkflow.run, | ||
"custom", | ||
id="forcing-tool-use-workflow-custom", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Custom result: {result3}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
40 changes: 40 additions & 0 deletions
40
openai_agents/agent_patterns/run_input_guardrails_workflow.py
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,40 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.input_guardrails_workflow import ( | ||
InputGuardrailsWorkflow, | ||
) | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute a workflow with a normal question (should pass) | ||
result1 = await client.execute_workflow( | ||
InputGuardrailsWorkflow.run, | ||
"What's the capital of California?", | ||
id="input-guardrails-workflow-normal", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Normal question result: {result1}") | ||
|
||
# Execute a workflow with a math homework question (should be blocked) | ||
result2 = await client.execute_workflow( | ||
InputGuardrailsWorkflow.run, | ||
"Can you help me solve for x: 2x + 5 = 11?", | ||
id="input-guardrails-workflow-blocked", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Math homework result: {result2}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
31 changes: 31 additions & 0 deletions
31
openai_agents/agent_patterns/run_llm_as_a_judge_workflow.py
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,31 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.llm_as_a_judge_workflow import ( | ||
LLMAsAJudgeWorkflow, | ||
) | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute a workflow | ||
result = await client.execute_workflow( | ||
LLMAsAJudgeWorkflow.run, | ||
"A thrilling adventure story about pirates searching for treasure", | ||
id="llm-as-a-judge-workflow-example", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
40 changes: 40 additions & 0 deletions
40
openai_agents/agent_patterns/run_output_guardrails_workflow.py
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,40 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.output_guardrails_workflow import ( | ||
OutputGuardrailsWorkflow, | ||
) | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute a workflow with a normal question (should pass) | ||
result1 = await client.execute_workflow( | ||
OutputGuardrailsWorkflow.run, | ||
"What's the capital of California?", | ||
id="output-guardrails-workflow-normal", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Normal question result: {result1}") | ||
|
||
# Execute a workflow with input that might trigger sensitive data output | ||
result2 = await client.execute_workflow( | ||
OutputGuardrailsWorkflow.run, | ||
"My phone number is 650-123-4567. Where do you think I live?", | ||
id="output-guardrails-workflow-sensitive", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Sensitive data result: {result2}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
31 changes: 31 additions & 0 deletions
31
openai_agents/agent_patterns/run_parallelization_workflow.py
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,31 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.parallelization_workflow import ( | ||
ParallelizationWorkflow, | ||
) | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute a workflow | ||
result = await client.execute_workflow( | ||
ParallelizationWorkflow.run, | ||
"Hello, world! How are you today?", | ||
id="parallelization-workflow-example", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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,29 @@ | ||
import asyncio | ||
|
||
from temporalio.client import Client | ||
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin | ||
|
||
from openai_agents.agent_patterns.workflows.routing_workflow import RoutingWorkflow | ||
|
||
|
||
async def main(): | ||
# Create client connected to server at the given address | ||
client = await Client.connect( | ||
"localhost:7233", | ||
plugins=[ | ||
OpenAIAgentsPlugin(), | ||
], | ||
) | ||
|
||
# Execute a workflow | ||
result = await client.execute_workflow( | ||
RoutingWorkflow.run, | ||
"Bonjour! Comment allez-vous aujourd'hui?", | ||
id="routing-workflow-example", | ||
task_queue="openai-agents-patterns-task-queue", | ||
) | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left two comments at #226 that apply here as well