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

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:

bool

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 agent

  • content (str) – Message content

  • message_type (MessageType) – Type of message being sent

  • metadata (Optional[Dict]) – Additional information about the message

Return type:

Message

Returns:

The sent message

Raises:
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.

Parameters:

message (Message) – The message to process

Return type:

Optional[Message]

Returns:

Optional response message

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.

Parameters:

duration (int) – Cooldown duration in seconds

Return type:

None

is_in_cooldown()

Check if agent is in cooldown.

Return type:

bool

Returns:

True if the agent is in cooldown, False otherwise

end_conversation(other_agent_id)

End conversation with another agent.

Parameters:

other_agent_id (str) – ID of the other agent in the conversation

Return type:

None

async can_send_message(receiver_id)

Check if agent can send message.

Parameters:

receiver_id (str) – ID of the receiving agent

Return type:

bool

Returns:

True if the agent can send a message, False otherwise

async can_receive_message(sender_id)

Check if the agent can receive a message from the sender.

Parameters:

sender_id (str) – ID of the sending agent

Return type:

bool

Returns:

True if the agent can receive a message, False otherwise

reset_cooldown()

Reset the cooldown state of the agent.

This method resets the agent’s cooldown state, allowing it to send and receive messages immediately.

Return type:

None