Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/user-guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,20 @@ import logging
from strands import Agent
from strands_tools import shell

logger = logging.getLogger("my_agent")
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()

# Define a simple callback handler that logs instead of printing
tool_use_ids = []
def callback_handler(**kwargs):
if "data" in kwargs:
# Log the streamed data chunks
logger.info(kwargs["data"], end="")
# Log the streamed chunks
logger.info(f"{kwargs['delta']}")
elif "current_tool_use" in kwargs:
tool = kwargs["current_tool_use"]
if tool["toolUseId"] not in tool_use_ids:
# Log the tool use
logger.info(f"\n[Using tool: {tool.get('name')}]")
logger.info(f"[Using tool: {tool.get('name')}]")
tool_use_ids.append(tool["toolUseId"])

# Create an agent with the callback handler
Expand All @@ -526,7 +527,7 @@ agent = Agent(
result = agent("What operating system am I using?")

# Print only the last response
print(result.message)
print(f"\n{result}")
```

The callback handler is called in real-time as the agent thinks, uses tools, and responds.
Expand Down