Skip to content

coordinator

MCP agent management utilities for the MADA multi-agent system.

This module defines the MCPAgentManager class, a reusable base for managing agents that interact with MCP (Model Context Protocol) tool servers.

Responsibilities of this module include: - Creating and configuring chat agents with model and instruction settings - Instantiating an OpenAI-compatible model client for use by agents

Typical usage

Subclass MCPAgentManager to implement specific session logic (e.g., console or web UI), then call create_chat_agent() with an AgentConfig to instantiate tool-using agents.

MCPAgentManager

Base class for managing agent creation with MCP (Model Context Protocol) tools.

This class provides shared functionality for creating agents and managing model client configuration. It can be extended by different implementations for console or web UI integrations.

Attributes:

Name Type Description
model_config ModelConfig

Configuration for the model client.

timeout int

Timeout in seconds for server operations.

model_client BaseChatClient

Client for generating chat responses.

Methods:

Name Description
create_chat_agent

Given an agent configuration, create an Agent.

Source code in src/mada/core/coordinator.py
class MCPAgentManager:
    """
    Base class for managing agent creation with MCP (Model Context Protocol) tools.

    This class provides shared functionality for creating agents and managing
    model client configuration. It can be extended by different implementations
    for console or web UI integrations.

    Attributes:
        model_config (ModelConfig): Configuration for the model client.
        timeout (int): Timeout in seconds for server operations.
        model_client (BaseChatClient): Client for generating chat responses.

    Methods:
        create_chat_agent: Given an agent configuration, create an Agent.
    """

    def __init__(
        self, model_config: Optional[ModelConfig] = None, timeout: int = 86400
    ):
        """
        Initialize the MCP agent manager.

        Args:
            model_config: Configuration for the model client. If None, uses environment variables.
            timeout: Timeout in seconds for server operations.
        """
        self.model_config = model_config or ModelConfig()
        self.timeout = timeout
        self.model_client = self._setup_model_client()

    def _setup_model_client(self) -> BaseChatClient:
        """
        Instantiate and return the chat client.

        Returns:
            A configured model client ready to be used by agents.
        """
        return chat_client_factory.create(self.model_config)

    async def create_chat_agent(
        self,
        agent_config: AgentConfig,
        tools: List[Any] = None,
        **kwargs: Dict[str, Any],
    ) -> Agent:
        """
        Create an Agent from configuration.

        Args:
            agent_config: Configuration for the agent.
            tools: List of tools to provide to the agent.
            **kwargs: Additional arguments to pass to Agent constructor.

        Returns:
            The created Agent.
        """
        return self.model_client.as_agent(
            name=agent_config.agent_name,
            instructions=agent_config.instructions,
            tools=tools or [],
            **kwargs,
        )

__init__(model_config=None, timeout=86400)

Initialize the MCP agent manager.

Parameters:

Name Type Description Default
model_config Optional[ModelConfig]

Configuration for the model client. If None, uses environment variables.

None
timeout int

Timeout in seconds for server operations.

86400
Source code in src/mada/core/coordinator.py
def __init__(
    self, model_config: Optional[ModelConfig] = None, timeout: int = 86400
):
    """
    Initialize the MCP agent manager.

    Args:
        model_config: Configuration for the model client. If None, uses environment variables.
        timeout: Timeout in seconds for server operations.
    """
    self.model_config = model_config or ModelConfig()
    self.timeout = timeout
    self.model_client = self._setup_model_client()

create_chat_agent(agent_config, tools=None, **kwargs) async

Create an Agent from configuration.

Parameters:

Name Type Description Default
agent_config AgentConfig

Configuration for the agent.

required
tools List[Any]

List of tools to provide to the agent.

None
**kwargs Dict[str, Any]

Additional arguments to pass to Agent constructor.

{}

Returns:

Type Description
Agent

The created Agent.

Source code in src/mada/core/coordinator.py
async def create_chat_agent(
    self,
    agent_config: AgentConfig,
    tools: List[Any] = None,
    **kwargs: Dict[str, Any],
) -> Agent:
    """
    Create an Agent from configuration.

    Args:
        agent_config: Configuration for the agent.
        tools: List of tools to provide to the agent.
        **kwargs: Additional arguments to pass to Agent constructor.

    Returns:
        The created Agent.
    """
    return self.model_client.as_agent(
        name=agent_config.agent_name,
        instructions=agent_config.instructions,
        tools=tools or [],
        **kwargs,
    )