Can i have an agent that has access with 2 tools b...
# ask-ai
a
Can i have an agent that has access with 2 tools but the output of the first tool updates the second tool dynamically
t
Thanks for reaching out, Ali. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can have an agent access two tools where the output from the first tool dynamically updates the second one. Here’s how this can work: • Dynamic Tool Updates: Tools can be updated or added on the fly, based on what the first tool produces. • Shared State: Both tools can share and update a common state, so the output from one naturally influences the other. • Sequential Execution: The agent can run the tools one after the other, with the first tool’s output feeding into the second tool’s input. If you have a particular scenario in mind or want some help setting this up, feel free to reach out—I’m here to help! Sources: tool_calling/update_tools.py | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee... | examples/src/comprehensive_test.ts | Tool definition and use | LiveKit docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/...
a
give me an example where tool 1 outputs a schema; that schema is the schema needed to call tool 2 the agent needs to call tool 1 then speak then call the updated version of tool 2
t
Here’s a friendly example to help you understand how Tool 1 can output a schema, and then Tool 2 updates dynamically based on that schema: 1. Tool 1 Outputs a Schema: Tool 1 creates a schema on the fly, like a JSON schema for a function. For instance:
Copy code
{
  "type": "function",
  "name": "get_weather",
  "description": "Get weather for a given location.",
  "parameters": {
    "type": "object",
    "properties": {
      "location": {
        "type": "string",
        "description": "City and country e.g. New York"
      }
    },
    "required": [
      "location"
    ]
  }
}
1. Tool 2 Dynamically Updates: Then, the agent takes the schema from Tool 1 and uses it to register or update Tool 2 while it’s running. Here’s how it looks:
Copy code
await activity.update_tools([
    function_tool(handler, raw_schema=generated_schema)
])
So, in this process: • Tool 1 generates the schema dynamically for you. • The agent reads that schema and updates Tool 2 using the
update_tools()
method. • After that, the agent can call Tool 2 with the fresh, updated schema. If you’d like me to walk you through more details or tailor this to your specific needs, just let me know—I’m here to help! Sources: Tool definition and use | LiveKit docs | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee... | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...
a
noo.. imagine something like this: tool 1 outputs a weather and a json of that weather; tool 2 takes that json as input
t
I'm happy to help explain how LiveKit works with tools returning structured data like JSON, which the agent can then process. While tools don’t pass their output directly to each other, the agent plays a key role in managing this flow. It uses the output from Tool 1 to decide if and how to call Tool 2. Here’s a simple example to illustrate: 1. Tool 1: Provides weather data in a JSON format, like this:
Copy code
{
  "temperature": "70°F",
  "condition": "Sunny"
}
1. Agent: Takes this JSON and decides to invoke Tool 2. 2. Tool 2: Uses the JSON input to perform further actions, such as storing the data or making another API call. If you'd like, I’m here to guide you through implementing this flow or chat about your specific use case—just let me know! Sources: Tool definition and use | LiveKit docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | agents/src/voice/generation_tools.test.ts
a
give me pseudo code!!
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!