Skip to content
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

Support for Manual Execution of Tool Calls for Third-Party Integration #188

Closed
mikuh opened this issue Mar 17, 2025 · 1 comment
Closed
Labels
question Question about using the SDK

Comments

@mikuh
Copy link

mikuh commented Mar 17, 2025

Please read this first

  • Have you read the docs?Agents SDK docs yes
  • Have you searched for related issues? Others may have had similar requesrs yes

Question

Currently, when using an agent, tool functions decorated with @function_tool are automatically invoked. I have a specific requirement where I need to send the function call details to a third-party system for execution. After receiving the results from the third party, I want to manually add these results to the messages list.

Steps to Reproduce:

Define a tool function using the @function_tool decorator.
Run the agent using Runner.run_streamed with a prompt that triggers the tool function.
Observe that the tool function is automatically called.

Expected Behavior:

A configuration option or method to disable automatic tool calls so that the function call information is exposed to the user instead of being automatically executed.
The user should then be able to send this information to a third-party system for execution, receive the result, and manually insert the result back into the message flow.

Proposed Solution:

Provide a configuration option in the agent setup to disable automatic tool execution.
Alternatively, allow the agent to output the tool call details as part of its response, letting the user decide when to execute the tool function and how to handle the results.

@mikuh mikuh added the question Question about using the SDK label Mar 17, 2025
@rm-openai
Copy link
Collaborator

In general, the model expects that if it sends you a tool call, the input on the next turn has the results for the tool call. So you'd definitely need to add the responses.

You could directly create a FunctionTool instead of using the decorator. For example:

def run_my_tool(name: str, json_args: str) -> str:
   return call_3rd_party(name, json) 
 
tool_list = []
for tool in third_party_service.tools():
    async def on_invoke_tool( ctx: RunContextWrapper[Any], input: str) -> str:
        return run_my_tool(ctx.tool_name, input)
 
    tool_list.append(FunctionTool(
        name=tool.name, 
        params_json_schema=tool.json_schema(),
        on_invoke_tool=on_invoke_tool,
    ))
 
agent = Agent(
    ...,
    tools=tool_list,
)

@mikuh mikuh closed this as completed Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

2 participants