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

Manual intervention on tool calls #195

Open
vikigenius opened this issue Dec 9, 2024 · 3 comments
Open

Manual intervention on tool calls #195

vikigenius opened this issue Dec 9, 2024 · 3 comments

Comments

@vikigenius
Copy link

It seems like for all agents, tool calls are automatic. I.e Pydantic automatically runs the tool and passes the result back and continues the run.

Can I manually intervene such that I want to manually run the tools and manage if I want to continue the run or not depending on the result?

@samuelcolvin
Copy link
Member

This would be solved by #142.

@dmontagu this is an argument to keep the ctx.end_run(result) idea.

@vikigenius
Copy link
Author

@samuelcolvin I am not sure if I understand the PR. Is it ending the run after the tool execution or before?

For example, if I don't use any framework in OpenAI I have to manually inspect the tool_calls and call them myself. I want to be able to do that here for some agents.

@samuelcolvin
Copy link
Member

If you want to simply end the with specific data type, just use result_type, you can change the name of that tool with result_tool_name, e.g.:

from pydantic import BaseModel

from pydantic_ai import Agent


class CityLocation(BaseModel):
    city: str
    country: str


agent = Agent('openai:gpt-4', result_type=CityLocation, result_tool_name='city_location')
result = agent.run_sync('Where the olympics held in 2012?')
print(result.data)
#> city='London' country='United Kingdom'
print(result.cost())

If you want the option to end the run within an arbitrary tool, call ctx.stop_run(result) within a tool once #142 is implemented. Of course, you can call this anywhere in your function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants