Part 6: Install the framework

After building the loop directly, we can compare frameworks that provide more structure. The first one is OpenAI Agents SDK.

uv add openai-agents

Import the agent class and the helper that turns Python functions into tools:

from agents import Agent, function_tool

The SDK still needs the same ingredients: instructions, a model, and tools.

Wrap the FAQ tools

Start with the explicit version. Wrap each method with function_tool:

tools = [
    function_tool(search_tools.search),
    function_tool(search_tools.add_entry),
]

Then create the agent:

agent = Agent(
    name="faq_agent",
    instructions=developer_prompt,
    tools=tools,
    model="gpt-4o-mini"
)

This is close to the code we wrote for the plain OpenAI API, but the SDK manages more of the agent run for you.

Run it from the notebook

The workshop uses a toyaikit runner to keep the notebook interaction the same as before. The runner is for display and testing, not the main SDK idea.

from toyaikit.chat.runners import OpenAIAgentsSDKRunner

runner = OpenAIAgentsSDKRunner(
    chat_interface=chat_interface,
    agent=agent
)

The Agents SDK runner is async, so use await in Jupyter:

await runner.run()

Try the same prompts:

  • How do I do well in module 1?
  • How about Docker?
  • Add this back to FAQ

The behavior should look familiar because the underlying tools and instructions are the same.

Wrap all instance methods

Wrapping every method by hand becomes annoying once the tool class grows. toyaikit.tools.wrap_instance_methods applies a wrapper to every public method on an object.

from toyaikit.tools import wrap_instance_methods

tools = wrap_instance_methods(function_tool, search_tools)

This is equivalent to wrapping search_tools.search and search_tools.add_entry manually. If you add another public method to SearchTools, it will be included automatically.

Recreate the agent with the generated list:

agent = Agent(
    name="faq_agent",
    instructions=developer_prompt,
    tools=tools,
    model="gpt-4o-mini"
)

To learn more, look at OpenAIAgentsSDKRunner. When you use the SDK in your own app, decide how much runner logic you want to own.

Handoffs

We do not build a multi-agent example here, but one Agents SDK feature is worth knowing: handoffs. A handoff lets one agent delegate to another agent for a specific task.

You can model this yourself with a tool that calls another agent. Agents SDK gives you a built-in abstraction for the same pattern. The official docs describe it in the handoffs guide.

We stay with one FAQ agent here because the workshop goal is to compare the basic tool loop across implementations.

Questions & Answers (0)

Sign in to ask questions