Skip to content

Use tool output as agent output #117

Closed
@TimoVink

Description

@TimoVink

Is there some equivalent to AutoGen's reflect_on_tool_use=False? That is: Some way for an agent to use the output of one of its tools as its own output, without needing another roundtrip to the LLM?

Worked example:

# Untested code, just illustrative

class LoremModel(BaseModel):
    paragraph: str

@function_tool
def generate_lorem(n: int) -> List[LoremModel]:
    '''Generate `n` paragraphs of lorem ipsum'''
    # omitted

agent = Agent(
    name='Lorem Agent',
    tools=[generate_lorem],
    output_type=List[LoremModel],
)

await Runner.run(agent, 'Generate 1000 paragraphs of lorem ipsum')

I believe the way this works is:

  1. Prompt gets sent up to the LLM
  2. LLM responds requesting invocation of generate_lorem(1000)
  3. We execute that function and now have 1000 paragraphs of lorem ipsum in memory
  4. We send these 1000 paragraphs back up to the LLM
  5. The LLM generates a final response to the user prompt, which is just those same paragraphs of lorem ipsum again.

In practice we already have our answer after step 3, but then have this extra roundtrip in steps 4&5, which can get expensive in terms of both tokens and time if the output from our tool is large.

Is there functionality or design pattern to work around this? I think it would really help push the composability of agents even further than you already have with this SDK!

Real world usecase: I have an agent whose goal it is to retrieve a chunky piece of content. It has ~5 tools at its disposal. The "main" tool actually retrieves the data, the other tools help the agent determine the correct parameters with which to invoke the main tool. I would like to then use this "data retrieval agent" inside other agents which can then use this dataset to do interesting things.

I can work around this by making my "data retrieval agent" only return the correct parameters with which to call the main tool, and leave the actual retrieval to other agents, but then it feels like my agent isn't encapsulating a nice isolated chunk of work.

Love the library so far, thanks for your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions