Files
Pietro Zullo 18f51eddb8 Feat: python/restructure (#318)
* move: session

* move: client

* move:config

* move: exceptions

* move: connectors -> client.connectors

* move: task_managers -> client.task_managers

* move: observability -> agents.observability

* move: middleware -> client.middleware

* move: managers -> agents.managers

* move: auth -> client.auth

* move: adapters -> agents.adapters

* test: bc test

* test: bc test

* chore: remove relative imports

* fix tests

* chore: update docs

* chore: deprecation warnings

* chore: fix dangerous non absolute import

* fix: remove legacy imports

* telemetry
2025-10-17 20:09:19 +02:00

62 lines
1.6 KiB
Python

"""
Base agent interface for MCP tools.
This module provides a base class for agents that use MCP tools.
"""
from abc import ABC, abstractmethod
from typing import Any
from mcp_use.client.session import MCPSession
class BaseAgent(ABC):
"""Base class for agents that use MCP tools.
This abstract class defines the interface for agents that use MCP tools.
Agents are responsible for integrating LLMs with MCP tools.
"""
def __init__(self, session: MCPSession):
"""Initialize a new agent.
Args:
session: The MCP session to use for tool calls.
"""
self.session = session
@abstractmethod
async def initialize(self) -> None:
"""Initialize the agent.
This method should prepare the agent for use, including initializing
the MCP session and setting up any necessary components.
"""
pass
@abstractmethod
async def run(self, query: str, max_steps: int = 10) -> dict[str, Any]:
"""Run the agent with a query.
Args:
query: The query to run.
max_steps: The maximum number of steps to run.
Returns:
The final result from the agent.
"""
pass
@abstractmethod
async def step(self, query: str, previous_steps: list[dict[str, Any]] | None = None) -> dict[str, Any]:
"""Perform a single step of the agent.
Args:
query: The query to run.
previous_steps: Optional list of previous steps.
Returns:
The result of the step.
"""
pass