is it possible to use parallel tool calls with mcp...
# ask-ai
a
is it possible to use parallel tool calls with mcps?
t
Thanks for reaching out, Ian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Great question! Yes, you can definitely use parallel tool calls with MCPS in LiveKit. To get this going, just set the
parallel_tool_calls=True
parameter when you’re initializing your LLM instance. Here’s a quick example:
Copy code
from livekit.plugins import openai

session = AgentSession(
    llm=openai.LLM.with_x_ai(
        model="grok-2-public",
        parallel_tool_calls=True  # This turns on parallel execution of tool calls
    ),
    # ... other agent components (TTS, STT, etc.)
)
This handy feature works with a bunch of LLM providers that LiveKit supports, like OpenAI, Anthropic, and more. Just a heads-up—make sure your chosen LLM provider and backend actually support parallel tool calling so everything runs smoothly. Sources: Groq LLM integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-anthropic/livekit/plugins/anthropic/llm.py | xAI LLM integration guide | LiveKit Docs | DeepSeek LLM integration guide | LiveKit Docs | Anthropic Claude LLM integration guide | LiveKit Docs
a
how does parallel_tool_calls work? How does the llm know to submit multiple tool calls at the same time instead of in multiple sequetial calls?
t
Hey there! Just wanted to share a bit about the
parallel_tool_calls
parameter in LiveKit. When you set this to
True
, it lets the LLM make multiple tool calls at the same time instead of one after the other. It uses some cool asynchronous programming tricks like
asyncio.gather()
to run tasks side-by-side—think of fetching weather info for different cities all at once—which helps speed things up. The LLM figures out which calls can run together by checking if the tasks are independent. So, if one task doesn’t rely on another’s output, they can happen simultaneously. Behind the scenes, the backend passes the
parallel_tool_calls
flag to the LLM provider’s API, which then takes care of running everything smoothly. We’ve also built error handling that keeps things tidy—if one tool call hits a snag, the others can still finish okay, and any issues are caught individually. Plus, if a tool call is taking too long, it can be canceled nicely without causing a fuss. One thing to keep in mind: whether parallel tool calls actually work depends on the LLM provider supporting this feature. LiveKit gives you the option to set it up, but the provider’s API is the one that handles the actual execution. Sources: xAI LLM integration guide | LiveKit Docs | Fireworks AI LLM integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-mistralai/livekit/plugins/mistralai/llm.py | DeepSeek LLM integration guide | LiveKit Docs | Together AI LLM integration guide | LiveKit Docs