sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

Add documentation: Patterns for handling large tool call outputs

Open arronbailiss opened this issue 8 months ago • 3 comments

Summary

Document recommended patterns for handling large (multi-megabyte) tool call outputs so agent context is not polluted or exhausted.

Related: https://github.com/strands-agents/samples/issues/244

Patterns to document

1. File Reference Pattern

Write large output to disk, return only the file path to the agent. Agent then uses cat, grep, jq etc. to query data lazily.

2. AfterToolCallEvent Hook

Intercept tool results via hooks and truncate/summarize before they enter context.

3. Wrapper/Pipeline Tool

Chain tools internally inside a single tool so only the compact final result enters agent context.

References

  • Hooks docs: https://strandsagents.com/docs/user-guide/concepts/agents/hooks/
  • Tool Executors: https://strandsagents.com/docs/user-guide/concepts/tools/executors/

arronbailiss avatar Apr 01 '26 17:04 arronbailiss

In addition to docs that we'll do first, lets also brainstorm around if there is an opportunity to provide constructs in the SDK itself to simplify this kind of pattern.

notowen333 avatar Apr 21 '26 16:04 notowen333

This will likely be resolved through a context management best practices section after the context management optimization roadmap.

lizradway avatar Apr 21 '26 19:04 lizradway

Closing out, considering this done from https://strandsagents.com/docs/user-guide/concepts/plugins/context-offloader/

lizradway avatar Jul 01 '26 16:07 lizradway