-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Bug Report
Description
When using Agent with tools= and OpenAIChatClient, the agent fails with Object of type function is not JSON serializable on agent.run(). The raw Python function object is being included in the JSON payload sent to the OpenAI API instead of being converted to a tool/function schema.
This happens regardless of whether api_key is a string or callable.
Error
TypeError: Object of type function is not JSON serializable
Wrapped as:
agent_framework.exceptions.ServiceResponseException: <class 'agent_framework.openai._chat_client.OpenAIChatClient'> service failed to complete the prompt: Object of type function is not JSON serializable
Minimal Reproduction
import asyncio
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
client = OpenAIChatClient(
api_key="your-key",
model_id="gpt-5-mini",
)
def greet(name: str) -> str:
"""Say hello."""
return f"Hello {name}"
agent = Agent(client=client, instructions="You are helpful.", tools=[greet])
async def main():
r = await agent.run("greet Alice") # <-- fails here
print(r.text)
asyncio.run(main())Observations
- Fails with both string and callable
api_key - Works when
tools=is omitted (no tools) - The "function" in the error refers to the Python tool function object itself, not the API key
- Something in the tool registration/serialization path is passing the raw callable into the request body instead of its JSON schema definition
Environment
agent-framework-core==1.0.0b260212(commit65e77e52)- Also reproduced on commit
1e350ea2(PR Python: [BREAKING] PR2 — Wire context provider pipeline, remove old types, update all consumers #3850 merge) - Python 3.12
openai>=1.109.1
Reactions are currently unavailable