Common agentic patterns extended with Temporal's durable execution capabilities.
Adapted from OpenAI Agents SDK agent patterns
Before running these examples, be sure to review the prerequisites and background on the integration.
First, start the worker (supports all patterns):
uv run openai_agents/agent_patterns/run_worker.pyThen run individual examples in separate terminals:
Sequential agent execution with validation gates - demonstrates breaking complex tasks into smaller steps:
uv run openai_agents/agent_patterns/run_deterministic_workflow.pyRun multiple agents in parallel and select the best result - useful for improving quality or reducing latency:
uv run openai_agents/agent_patterns/run_parallelization_workflow.pyIterative improvement using feedback loops - generate content, evaluate it, and improve until satisfied:
uv run openai_agents/agent_patterns/run_llm_as_a_judge_workflow.pyUse agents as callable tools within other agents - enables composition and specialized task delegation:
uv run openai_agents/agent_patterns/run_agents_as_tools_workflow.pyRoute requests to specialized agents based on content analysis (adapted for non-streaming):
uv run openai_agents/agent_patterns/run_routing_workflow.pyPre-execution validation to prevent unwanted requests - demonstrates safety mechanisms:
uv run openai_agents/agent_patterns/run_input_guardrails_workflow.pyPost-execution validation to detect sensitive content - ensures safe responses:
uv run openai_agents/agent_patterns/run_output_guardrails_workflow.pyControl tool execution strategies - choose between different approaches to tool usage:
uv run openai_agents/agent_patterns/run_forcing_tool_use_workflow.pyA common tactic is to break down a task into a series of smaller steps. Each task can be performed by an agent, and the output of one agent is used as input to the next. For example, if your task was to generate a story, you could break it down into the following steps:
- Generate an outline
- Check outline quality and genre
- Write the story (only if outline passes validation)
Each of these steps can be performed by an agent. The output of one agent is used as input to the next.
Running multiple agents in parallel is a common pattern. This can be useful for both latency (e.g. if you have multiple steps that don't depend on each other) and also for other reasons e.g. generating multiple responses and picking the best one.
LLMs can often improve the quality of their output if given feedback. A common pattern is to generate a response using a model, and then use a second model to provide feedback. You can even use a small model for the initial generation and a larger model for the feedback, to optimize cost.
The mental model for handoffs is that the new agent "takes over". It sees the previous conversation history, and owns the conversation from that point onwards. However, this is not the only way to use agents. You can also use agents as a tool - the tool agent goes off and runs on its own, and then returns the result to the original agent.
Related to parallelization, you often want to run input guardrails to make sure the inputs to your agents are valid. For example, if you have a customer support agent, you might want to make sure that the user isn't trying to ask for help with a math problem.
You can definitely do this without any special Agents SDK features by using parallelization, but we support a special guardrail primitive. Guardrails can have a "tripwire" - if the tripwire is triggered, the agent execution will immediately stop and a GuardrailTripwireTriggered exception will be raised.
This is really useful for latency: for example, you might have a very fast model that runs the guardrail and a slow model that runs the actual agent. You wouldn't want to wait for the slow model to finish, so guardrails let you quickly reject invalid inputs.
The following patterns from the reference repository are not included in this Temporal adaptation:
- Streaming Guardrails: Requires streaming capabilities which are not yet available in the Temporal integration