Where should I define the name and description for subagents?

I have a subagent as defined below where I provide a name for the agent.

# agent_weather.py

from langchain.agents import create_agent

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}! There is no wind, temperature is 72 F, slight change of rain."

agent = create_agent(
    name="weather-agent",
    model="openai:gpt-5.4-mini",
    tools=[get_weather],
    system_prompt="You are a helpful weather forecast agent",
)

The subagent is utilized by the deep agent that is defined next. Notice the code for the deep agent also provides a name and description for the subagent.

# agent.py

from deepagents import create_deep_agent, CompiledSubAgent

from agent_weather import agent as agent_weather
from agent_divider import agent as agent_divider

def main():
    """Run the main agent."""

    weather_subagent = CompiledSubAgent(
        name="weather-subagent",
        description="Specialized agent for weather forecasts",
        runnable=agent_weather,
    )

    agent = create_deep_agent(
        model="openai:gpt-5.4-mini",
        system_prompt="You are a helpful assistant that uses subagents for specialized tasks",
        subagents=[weather_subagent],
    )

    result = agent.invoke(
        {
            "messages": [
                {
                    "role": "user",
                    "content": "Get the weather in paris",
                }
            ]
        }
    )

    print("\n--- Result ---\n", result)

    text = result["messages"][-1].content[0]["text"]
    print("\n--- Text ---\n", text)

So where should I define the name and description of the subagent in this code? Should it be in the subagent code itself or in the deep agent code or both?

Hello @wigging ,
The name and description that matter are on CompiledSubAgent. When you use CompiledSubAgent, the middleware’s _get_subagents() method extracts name and description exclusively from the CompiledSubAgent fields.

The name you pass to create_agent(name="weather-agent", ...) inside agent_weather.py is never read by the dispatch logic. It’s purely for observability (e.g., LangSmith traces)

Therefore, just define name and description only in CompiledSubAgent since that is what the main agent will use to decide when to invoke the subagent.

@wigging let me know if this is clear or if there are any questions?

Yes, this is clear. Thanks for the explanation. I guess it doesn’t hurt to define the name in create_agent and CompiledSubAgent. But like you said, it should at least be defined on CompiledSubAgent.