Skip to content

Commit 5183f52

Browse files
Add docs for customizng agent-as-tool (#504)
Co-authored-by: pakrym-oai <[email protected]>
1 parent 25f97f9 commit 5183f52

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/tools.md

+21
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ async def main():
259259
print(result.final_output)
260260
```
261261

262+
### Customizing tool-agents
263+
264+
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:
265+
266+
```python
267+
@function_tool
268+
async def run_my_agent() -> str:
269+
"""A tool that runs the agent with custom configs".
270+
271+
agent = Agent(name="My agent", instructions="...")
272+
273+
result = await Runner.run(
274+
agent,
275+
input="...",
276+
max_turns=5,
277+
run_config=...
278+
)
279+
280+
return str(result.final_output)
281+
```
282+
262283
## Handling errors in function tools
263284
264285
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.

0 commit comments

Comments
 (0)