Part 7: OpenAI Agents SDK
The first coding agent uses ToyAIKit for the tool loop. That is useful
for education, but for production you usually reach for a real agent
framework. The first one we try in the workshop is OpenAI Agents SDK.
Install the SDK
Install the package:
pip install openai-agents
Import the two pieces we use:
from agents import Agent, function_tool
Agent is the main abstraction. function_tool turns Python callables
into tools that the SDK can pass to the model.
Joke tool with the SDK
Start with the same joke function, this time with type hints and a docstring:
import random
@function_tool
def make_joke(name: str) -> str:
"""
Generates a personalized joke using the provided name.
Parameters:
name (str): The name to insert into the joke.
Returns:
str: A joke with the name included.
"""
jokes = [
f"Why did {name} bring a pencil to the party? Because he wanted to draw some attention!",
f"Did you hear about {name}'s bakery? Business is on a roll!",
f"{name} walked into a library and asked for a burger. The librarian said, 'This is a library.' So {name} whispered, 'Can I get a burger?'",
f"When {name} does push-ups, the Earth moves down.",
f"{name} told a chemistry joke... but there was no reaction.",
]
return random.choice(jokes)
The SDK uses the function signature and docstring to build the tool description. That is why type hints and docstrings matter.
If a function is already defined elsewhere and you cannot decorate it, wrap it after the fact:
make_joke_tool = function_tool(make_joke)
Create and run a joke agent
Define the prompt and agent:
joke_system_prompt = """
You can make funny and original jokes.
Find out the user's name to make the joke personalized.
"""
joke_agent = Agent(
name="JokeAgent",
instructions=joke_system_prompt,
tools=[make_joke],
model="gpt-4o-mini",
)
ToyAIKit still helps with the notebook chat interface, but the function
calling is now handled by OpenAI Agents SDK:
from toyaikit.chat import IPythonChatInterface
from toyaikit.chat.runners import OpenAIAgentsSDKRunner
interface = IPythonChatInterface()
runner = OpenAIAgentsSDKRunner(
chat_interface=interface,
agent=joke_agent,
)
The SDK runner is async:
await runner.run()
Try Tell me a joke. The agent should ask for your name, then call the
tool.
Coding agent tools
Now repeat the pattern for the Django coding agent. Copy a fresh template folder first:
cp -r django_template todo-agent
Create the tool object:
from pathlib import Path
import tools
agent_tools = tools.AgentTools(Path("todo-agent"))
You can wrap each method manually:
coding_agent_tools_list = [
function_tool(agent_tools.execute_bash_command),
function_tool(agent_tools.read_file),
function_tool(agent_tools.search_in_files),
function_tool(agent_tools.see_file_tree),
function_tool(agent_tools.write_file),
]
The workshop notebooks use a helper to avoid repeating that list:
from toyaikit.tools import wrap_instance_methods
coding_agent_tools_list = wrap_instance_methods(function_tool, agent_tools)
Both versions produce a list of SDK tools from the methods on
AgentTools.
Create the SDK coding agent
Use the same developer prompt from Part 5: Developer prompt:
coding_agent = Agent(
name="CodingAgent",
instructions=DEVELOPER_PROMPT,
tools=coding_agent_tools_list,
model="gpt-4o-mini",
)
Create the runner:
runner = OpenAIAgentsSDKRunner(
chat_interface=interface,
agent=coding_agent,
)
Run it:
await runner.run()
Type:
to-do list
The SDK version works, but it does not show every tool call in the same
visible way as the ToyAIKit Responses runner. It still reads and writes
files internally, but the notebook output appears in larger chunks because
that runner does not stream the intermediate steps.
Test the generated app
Run the generated project:
cd todo-agent
make run
Open http://127.0.0.1:8000/ and test the app. If a feature is missing,
continue the chat:
add functionality for removing completed items
This is the same loop as before. The framework changes, but the template, tools, and developer prompt stay the same.
Continue with Part 8: PydanticAI, Z.AI, and next steps.