Add docs for customizng agent-as-tool (#504)
Co-authored-by: pakrym-oai <pakrym@openai.com>
This commit is contained in:
parent
25f97f979b
commit
5183f528f4
1 changed files with 21 additions and 0 deletions
|
|
@ -259,6 +259,27 @@ async def main():
|
|||
print(result.final_output)
|
||||
```
|
||||
|
||||
### Customizing tool-agents
|
||||
|
||||
The `agent.as_tool` function is a convenience method to make it easy to turn an agent into a tool. It doesn't support all configuration though; for example, you can't set `max_turns`. For advanced use cases, use `Runner.run` directly in your tool implementation:
|
||||
|
||||
```python
|
||||
@function_tool
|
||||
async def run_my_agent() -> str:
|
||||
"""A tool that runs the agent with custom configs".
|
||||
|
||||
agent = Agent(name="My agent", instructions="...")
|
||||
|
||||
result = await Runner.run(
|
||||
agent,
|
||||
input="...",
|
||||
max_turns=5,
|
||||
run_config=...
|
||||
)
|
||||
|
||||
return str(result.final_output)
|
||||
```
|
||||
|
||||
## Handling errors in function tools
|
||||
|
||||
When you create a function tool via `@function_tool`, you can pass a `failure_error_function`. This is a function that provides an error response to the LLM in case the tool call crashes.
|
||||
|
|
|
|||
Loading…
Reference in a new issue