From 4919b4241ea2e4af5b5343edd59847ce3a2829be Mon Sep 17 00:00:00 2001 From: emaan-c Date: Sat, 11 Apr 2026 20:31:09 +0000 Subject: [PATCH] docs: add streaming direct tool calls documentation --- .../docs/user-guide/concepts/tools/index.mdx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/content/docs/user-guide/concepts/tools/index.mdx b/src/content/docs/user-guide/concepts/tools/index.mdx index 8fef0b3b0..aa17de0cd 100644 --- a/src/content/docs/user-guide/concepts/tools/index.mdx +++ b/src/content/docs/user-guide/concepts/tools/index.mdx @@ -186,6 +186,37 @@ Find the tool in the `agent.tools` array and call its `invoke()` method. You nee +#### Streaming Direct Tool Calls + +Direct tool calls support streaming, allowing you to observe execution events in real-time without recording to message history: + +```python +from strands import Agent, tool + +@tool +def analyze_data(query: str) -> str: + """Analyze data based on a query.""" + return f"Analysis complete for: {query}" + +agent = Agent(tools=[analyze_data]) + +# Async streaming +async for event in agent.tool.analyze_data.stream_async(query="sales trends"): + if "data" in event: + print(event["data"], end="") + +# Sync streaming +for event in agent.tool.analyze_data.stream(query="sales trends"): + if "data" in event: + print(event["data"], end="") +``` + +Streaming methods yield the same [tool events](../streaming/index.md#tool-events) as agent-level streaming. + +:::note +In Python, `agent.tool.my_tool(...)` is equivalent to TypeScript's `agent.tool.my_tool.invoke(...)`. Python uses `__call__` as the synchronous entry point, while TypeScript uses an explicit `.invoke()` method. +::: + ## Tool Executors