agentconnect.core.agent module¶
Base agent implementation for the AgentConnect framework.
This module provides the abstract base class for all agents in the system, defining the core functionality for agent identity, messaging, and interaction.
- class BaseAgent(agent_id, agent_type, identity, interaction_modes, capabilities=None, organization_id=None)¶
Bases:
ABC
Abstract base class for all agents in the system.
This class defines the core functionality that all agents must implement, including identity verification, message handling, and conversation management.
- Parameters:
agent_id (str)
agent_type (AgentType)
identity (AgentIdentity)
interaction_modes (List[InteractionMode])
capabilities (List[Capability])
organization_id (str | None)
- agent_id¶
Unique identifier for the agent
- identity¶
Agent’s decentralized identity
- metadata¶
Metadata about the agent
- capabilities¶
List of agent capabilities
- message_queue¶
Queue for incoming messages
- message_history¶
History of messages sent and received
- is_running¶
Whether the agent is currently running
- registry¶
Reference to the agent registry
- hub¶
Reference to the communication hub
- active_conversations¶
Dictionary of active conversations
- cooldown_until¶
Timestamp when cooldown ends
- pending_requests¶
Dictionary of pending requests
- async verify_identity()¶
Verify agent’s DID and update verification status.
This method verifies the agent’s decentralized identifier and updates the verification status accordingly.
- Return type:
- Returns:
True if the identity is verified, False otherwise
- Raises:
SecurityError – If identity verification fails
- async send_message(receiver_id, content, message_type=MessageType.TEXT, metadata=None)¶
Create and send a message through the hub.
- Parameters:
receiver_id (
str
) – ID of the receiving agentcontent (
str
) – Message contentmessage_type (
MessageType
) – Type of message being sentmetadata (
Optional
[Dict
]) – Additional information about the message
- Return type:
- Returns:
The sent message
- Raises:
RuntimeError – If the agent is not registered with a hub
ValueError – If the message cannot be routed
- async receive_message(message)¶
Receive and queue a message.
- Parameters:
message (
Message
) – The message to receive
- abstractmethod async process_message(message)¶
Process incoming message - must be implemented by subclasses.
This method processes an incoming message and generates a response. It must be implemented by subclasses to provide agent-specific message processing logic.
- async run()¶
Start the agent’s message processing loop.
This method starts the agent’s main processing loop, which continuously processes messages from the message queue until the agent is stopped.
- async join_network(network)¶
Join an agent network for agent-to-agent communication.
Note: Join_network is not required for MVP The registry handles all agent discovery and communication We keep it for future network functionality
- Parameters:
network – The network to join
- set_cooldown(duration)¶
Set a cooldown period for the agent.
- is_in_cooldown()¶
Check if agent is in cooldown.
- Return type:
- Returns:
True if the agent is in cooldown, False otherwise
- end_conversation(other_agent_id)¶
End conversation with another agent.
- async can_send_message(receiver_id)¶
Check if agent can send message.
- async can_receive_message(sender_id)¶
Check if the agent can receive a message from the sender.