feat: add AgentAsTool internal class#768
feat: add AgentAsTool internal class#768notowen333 wants to merge 3 commits intostrands-agents:mainfrom
Conversation
|
API Review Required This PR introduces new public API surface:
Per the API Bar Raising guidelines, this requires API review before merge. Please:
|
|
Documentation PR Required This PR adds new public API surface ( The PR description mentions "Will follow up once merged to generate valid snippets" - however, documentation should be prepared alongside the feature. Please provide a link to the documentation PR or explain why documentation is not needed before merging. |
Review SummaryAssessment: Request Changes This is a well-implemented feature that brings Python SDK parity for the agent-as-tool pattern. The code is clean, well-documented, and comprehensively tested. However, there are a few items that need to be addressed before merging. Review Categories
The implementation follows the Python SDK patterns well and the streaming/snapshot approach is solid. |
… session manager in agent-as-tool
Updated ReviewAssessment: Request Changes → pending process items Thanks for addressing the session manager validation! The implementation is solid with comprehensive test coverage. ✅ Resolved
|
There was a problem hiding this comment.
I'm focusing on api review; someone else should review implementation
Final ReviewAssessment: Approve (pending API review completion) The implementation has been refined and the PR description now provides comprehensive API documentation. ✅ Implementation Quality
✅ PR DescriptionThe updated description now includes:
Public API Surface
The code is well-structured and follows Python SDK patterns. Ready for merge once API review by @zastrowm is complete. |
Description
Adding an
asToolmethod to theAgentclass, matching what was released to python: https://github.com/strands-agents/sdk-python/blob/main/src/strands/agent/_agent_as_tool.pyThe feature that this implementation is missing is Interrupts because this is a gap in the sdk-typescript.
Otherwise this implementation closely follows python and handles streaming, ToolResults, and preserve context in the same way. This implementation is able to take advantage of snapshots which are not available in python.
This PR also adds the sugar we have in python to automatically convert agents in the tools array.
Motivation
Multi-agent orchestration requires a parent agent to delegate subtasks to specialized child agents. Until now, there was no built-in way to use one
Agentas a tool within another agent's tool set — users had to manually invoke sub-agents inside custom tool callbacks and marshal results themselves.This PR introduces
Agent.asTool()and automatic agent wrapping in thetoolsarray, making agent delegation a first-class pattern.Public API Changes
Agent.asTool(options?)— wraps an agent as a tool for use by another agent:preserveContextcontrols whether the sub-agent retains conversation history across invocations:false(default) — resets messages, state, and system prompt before each call using thesessionsnapshot presettrue— accumulates context across calls, useful for agents that need memory of prior interactionsA
SessionManageron the sub-agent is incompatible withpreserveContext: falseand will throw at construction time.Agent.sessionManager— the agent now exposes itsSessionManageras a public readonly property (detected from either thesessionManagerorpluginsconfig fields).Use Cases
Specialized delegation — a writer agent delegates research to a researcher agent, each with their own tools and system prompts:
Stateful sub-agents — a sub-agent that builds context over multiple calls:
Related Issues
#765
Documentation PR
Will follow up once merged to generate valid snippets.
Type of Change
New feature
Testing
Added unit tests and an integration test.
npm run checkChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.