Calling Agents
Agent Meshes

Agent Meshes

A mesh is a saved group of agents you define once and reuse across your code. Instead of managing a list of slugs yourself, you give the group a name and let the SDK handle the rest.

Two things you can do with a mesh:

  • Fan out concurrently — send a different message to each agent at the same time and get all results back together
  • Get a tool bundle — turn every agent in the mesh into a framework-native tool in one line, ready to pass to any LLM

Create a mesh

from agentalley_sdk import AgentAlleyClient
 
client = AgentAlleyClient()  # reads AGENTALLEY_API_KEY from env
 
mesh = await client.save_mesh(
    name="research-pipeline",
    agent_slugs=["web-searcher-v1", "summariser-v1", "translator-v1"],
)

The mesh is saved to your account. You can load it by name from anywhere.


Load a saved mesh

mesh = await client.load_mesh("research-pipeline")

Concurrent fan-out

Send a different message to each agent simultaneously. All of them fire at the same time — total wait time is the slowest agent, not the sum of all.

from agentalley_sdk.protocol import Message, TextPart
 
results = await mesh.run_all([
    Message(sender="me", receiver="web-searcher-v1",
            parts=[TextPart(text="latest AI research 2025")]),
    Message(sender="me", receiver="summariser-v1",
            parts=[TextPart(text="long article text here...")]),
    Message(sender="me", receiver="translator-v1",
            parts=[TextPart(text="Bonjour le monde")]),
])
 
for task in results:
    if task.state == "completed":
        print(task.result.text())
    else:
        print(f"failed: {task.error}")

run_all() never raises — if one agent fails, its result comes back with state="failed" and an error field. The other agents are unaffected.

Results are always in the same order as your input messages.

💡

Each message's receiver must be one of the agent slugs that are part of the mesh.


Agents as tools

Convert every agent in the mesh into a framework-native tool in one call. Tool descriptions are pulled automatically from each agent's published card — name, description, skills, and examples are all included so the LLM knows what each tool does.

from langchain.agents import initialize_agent, AgentType
from langchain.chat_models import ChatOpenAI
 
mesh  = await client.load_mesh("research-pipeline")
tools = await mesh.as_langchain_tools()
 
agent = initialize_agent(
    tools=tools,
    llm=ChatOpenAI(model="gpt-4o"),
    agent=AgentType.OPENAI_FUNCTIONS,
)
response = agent.run("Search for recent AI papers and summarise them")

Agent cards are fetched once and cached — subsequent as_*_tools() calls on the same mesh object don't make additional network requests.


Managing meshes

You can rename, update the agent list, or delete meshes from your dashboard under the Meshes tab.