Interface
Defines the abstract base class AgentInterface for all agent implementations, now with MCP and A2A support.
AgentInterface(name, instruction, description=None, lm_invoker=None, config=None, **kwargs)
Bases: ABC
A general and minimal interface for agent implementations.
Defines core execution methods (__init__
, run
, arun
, arun_stream
).
Concrete subclasses must implement all abstract methods.
Initializes the agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the agent. |
required |
instruction |
str
|
The core directive or system prompt for the agent. |
required |
description |
str | None
|
Human-readable description. Defaults to instruction if not provided. |
None
|
lm_invoker |
BaseLMInvoker | None
|
The language model invoker to use for LLM interactions. Defaults to None. |
None
|
config |
BaseAgentConfig | None
|
Additional configuration for the agent. |
None
|
**kwargs |
Any
|
Additional keyword arguments for concrete implementations. |
{}
|
add_mcp_server(mcp_config)
abstractmethod
Adds a new MCP server configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mcp_config |
dict[str, dict[str, Any]]
|
Dictionary containing server name as key and its configuration as value. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If mcp_config is empty or None, or if any server configuration is invalid. |
KeyError
|
If any server name already exists in the configuration. |
arun(query, **kwargs)
abstractmethod
async
Asynchronously runs the agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The input query for the agent. |
required |
**kwargs |
Any
|
Additional keyword arguments for execution. |
{}
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dict containing at least {'output': ...}. |
arun_stream(query, **kwargs)
abstractmethod
async
Asynchronously streams the agent's response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The input query. |
required |
**kwargs |
Any
|
Extra parameters for execution. |
{}
|
Yields:
Type | Description |
---|---|
AsyncGenerator[str | dict[str, Any], None]
|
Chunks of output (strings or dicts). |
register_a2a_agents(agents)
abstractmethod
Registers A2A agents from a list of AgentCards.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agents |
list[AgentCard]
|
A list of AgentCard instances. |
required |
run(query, **kwargs)
abstractmethod
Synchronously runs the agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The input query for the agent. |
required |
**kwargs |
Any
|
Additional keyword arguments for execution. |
{}
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dict containing at least {'output': ...}. |