-
Notifications
You must be signed in to change notification settings - Fork 214
enhancement(agent): add returnRunResult option to agent.asTool() to expose RunResult and interruptions #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 665a260 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…nContext for asTool.invoke
e0669a2
to
9ecdbc4
Compare
Thanks for sending this PR. I don't yet have a clear idea of the best approach for this issue, but at a glance, this PR doesn't seem like the best solution for the linked issues to me. When an agent is attached as a tool, it should behave as a tool. Therefore, exposing the agent's run result as a tool output sounds like a different type of tool definition. Also, the agent that calls the sub-agent as a tool shouldn't need to know the difference between agent tools and other types of tools. There are a few other things I am currently working on, but will check this issue sometime soon. |
Thanks for the quick intial feedback!...yep, totally agree that when an agent is used as a tool, it should behave like one. The flag felt like the simplest, least disruptive way to support these issues. When We only get the richer We could also ship an I guess the broader question is: since there are already other flags and possibly more coming wondering if it might be worth thinking about whether these kinds of options should live under an experimental umbrella, similar to how Cloudflare Workers support is presently marked. Just some thoughts. Happy to address changes or restart with a different approach. |
Ok, so as I understand, there's a bit of incompatibility between the two options:
When we talk about the last message from the agent, we're talking about the last message from the history that comes from the assistant, not the last message from the history? Any reason why we want the last message to strictly be from the assistant? |
@mhashas i've answered this in #247 (comment). thought this clarification belongs in #247 as #249 is the proposed implementation path that avoids needing a custom extractor. |
This adds a
returnRunResult
option toagent.asTool()
that allows developers to access the fullRunResult
of the sub-agent when invoked as a tool.By default,
asTool()
only returns the final output string of the sub-agent, which means any interruptions (e.g. approval requests vianeedsApproval
) are hidden from the parent agent.With this flag enabled:
RunResult
is returnedThis change is backward-compatible and opt-in. It does not affect any existing users of
asTool()
.Also, note that we have,
tools.mdx
to explain thereturnRunResult
flag.agentsAsTools.ts
to include anechoTool
usingreturnRunResult
.tool-use-behavior.ts
that demonstrates how to inspectRunResult.newItems
.Added tests to verify that:
asTool({ returnRunResult: true })
returns aRunResult
with the correctfinalOutput
.stopAtToolNames
works without needing acustomOutputExtractor
, fixing #247.RunContext
is properly used in.invoke()
to satisfy typing and test runtime behavior.Example usage:
Resolves #243 and also
Resolves #247 –
asTool()
now correctly returnsfinalOutput
withstopAtToolNames
, without requiring a custom extractorTested with
pnpm test
,pnpm link
, andpnpm build-check
.