Skip to content

Add return_direct=True support for @tool annotation for Langchain #2157

@kardiff18

Description

@kardiff18

Is your feature request related to a problem? Please describe.
I currently have Langchain code for agents that work great. I am looking to migrate the code and retain parity with the existing features. In the existing code, I use @tool(return_direct=True) for some of the tools. This allows us to bypass the second function call which would summarize/format the function response. We like to return the raw function response in some cases, especially where when we have multiple subagents that are communicating and they are deployed in different places.

As an example, we have AgentA whose tool1 is simply to get an answer from AgentB. In that case, the response from tool1 has already been formatted by AgentB and therefore the LLM, and we do not want to pay/wait for AgentA to ingest and re-generate tool1's response from AgentB. This duplicates cost, latency, and ultimately could change a perfectly good answer.

Describe the solution you'd like
Today, ADK supports Langchain tools and the @tool annotation. We would like it to also support @tool(return_direct=True).

Describe alternatives you've considered
I can achieve this today by using callbacks, but it is a bit of boilerplate code as opposed to just adding return_direct into the @tool annotation.

We also only do it conditionally for some functions and it would be best to declare this functionality in the function rather than writing a conditional callback which depends on the tool name, as this could be error-prone if it needed to be changed/fixed.

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK bottools[Component] This issue is related to tools

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions