-
Notifications
You must be signed in to change notification settings - Fork 661
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
Add method_tool
Functionality
#94
Comments
I'll take a look. For now there's a pretty simple workaround:
|
Hi @nathanmargaglio and @rm-openai, I've created pull request #137, which addresses the issue and includes tests to verify the changes. Please take a look and let me know if you have any feedback. Thanks! |
I have the similar problem. I need to pass chat_id to some of the tool functions for searching purpose. Currently I am doing this and it fails. I wonder if there's any better way that the tool functions can get class Tools:
def __init__(self, chat_uuid: str):
self.chat_uuid = chat_uuid
@function_tool(name_override="tell_time_tool", description_override="A tool that tells the current time.")
async def tell_time_tool(self) -> str:
return tell_time()
@function_tool(
name_override="ask_for_clarification_tool",
description_override="A tool that asks for clarification if user's request doesn't make sense.",
)
async def ask_for_clarification_tool(self) -> str:
return ask_for_clarification() And this is how I implement the agent. class TriageAgent(Agent):
def __init__(self, chat_uuid: str, input: any) -> None:
self.chat_uuid = chat_uuid
self.input = input
self.tool_collections = Tools(chat_uuid=chat_uuid)
self.tools = [self.tool_collections.tell_time_tool, self.tool_collections.ask_for_clarification_tool]
self.handoffs = []
self.agent = Agent(
name="Triage Agent",
instructions=INSTRUCTIONS,
tools=self.tools,
handoffs=self.handoffs,
)
async def run(self) -> None:
with trace(workflow_name="Triage Handling"):
# the chat pipeline starts with the triage agent
result = await Runner.run(starting_agent=self.triage_agent, input=self.input)
return result.final_output |
@WSQsGithub could you please share the error that you're getting? |
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for function 'tell_time_tool': In context=('properties', 'self'), schema must have a 'type' key.", 'type': 'invalid_request_error', 'param': 'tools[0].parameters', 'code': 'invalid_function_parameters'}} |
Yeah my pull request fixes it. |
I group my tools into classes, and they leverage attributes of the instantiated object to work properly. The
function_tool
decorator doesn't seem to support this. For example, the following works (as expected):But the following doesn't:
Running this produces an error like:
i.e., the
self
parameter isn't accounted for.There's probably a ton of different ways of approaching this, but I've been utilizing the class-based tool pattern quite extensively and I've found it works pretty well for keeping tooling clean and simple. I'm happy to consider alternative approaches, but if there was just a way to ignore the
self
parameter, then I think everything else would just work, no?The text was updated successfully, but these errors were encountered: