agentconnect.agents.ai_agent module

Independent AI Agent implementation for the AgentConnect decentralized framework.

This module provides an autonomous AI agent that can operate independently within a decentralized network, process messages, generate responses, discover other agents based on capabilities, and interact with those agents without pre-defined connections or central control. Each agent can potentially implement its own internal multi-agent structure while maintaining secure communication with other agents in the decentralized network.

class MemoryType(value)

Bases: str, Enum

Types of memory storage backends.

BUFFER = 'buffer'
class AIAgent(agent_id, name, provider_type, model_name, api_key, identity, capabilities=None, personality='helpful and professional', organization_id=None, interaction_modes=[InteractionMode.HUMAN_TO_AGENT, InteractionMode.AGENT_TO_AGENT], max_tokens_per_minute=70000, max_tokens_per_hour=700000, max_turns=20, is_ui_mode=False, memory_type=MemoryType.BUFFER, prompt_tools=None, prompt_templates=None, custom_tools=None, agent_type='ai', enable_payments=False, verbose=False, wallet_data_dir=None, external_callbacks=None, model_config=None)

Bases: BaseAgent

Independent AI Agent implementation that operates autonomously in a decentralized network.

This agent uses language models to generate responses, can discover and communicate with other agents based on their capabilities (not pre-defined connections), and can implement its own internal multi-agent structure if needed. It operates as a peer in a decentralized system rather than as part of a centrally controlled hierarchy.

Key features:

  • Autonomous operation with independent decision-making

  • Capability-based discovery of other agents

  • Secure identity verification and communication

  • Potential for internal multi-agent structures

  • Dynamic request routing based on capabilities

Parameters:
property hub

Get the hub property.

property registry

Get the registry property.

property prompt_tools

Get the prompt_tools property.

async process_message(message)

Process an incoming message autonomously and generate a response.

This method represents the agent’s autonomous decision loop, where it: :rtype: Optional[Message]

  • Verifies message security independently

  • Makes decisions on how to respond based on capabilities

  • Can dynamically discover and collaborate with other agents as needed

  • Maintains its own internal state and conversation tracking

  • Operates without central coordination or control

The agent can leverage its internal workflow (which may include its own multi-agent system) to generate appropriate responses and handle complex tasks that may require collaboration with other independent agents in the decentralized network.

Parameters:

message (Message)

Return type:

Message | None

set_cooldown(duration)

Set a cooldown period for the agent.

Return type:

None

Parameters:

duration (int)

reset_interaction_state()

Reset the interaction state of the agent. This resets both the cooldown state and the turn counter.

Return type:

None

async chat(query, conversation_id='standalone_chat', metadata=None)

Allows direct interaction with the agent without needing a CommunicationHub or AgentRegistry.

This method is useful for testing or using a single agent instance directly. It simulates a user query and returns the agent’s response, maintaining conversation history based on the conversation_id if memory is configured.

Parameters:
  • query (str) – The user’s input/query to the agent.

  • conversation_id (str) – An identifier for the conversation thread. Defaults to “standalone_chat”. Use different IDs to maintain separate conversation histories.

  • metadata (Optional[Dict]) – Optional metadata to pass to the workflow.

Return type:

str

Returns:

The agent’s response as a string.

Raises:
  • RuntimeError – If the workflow cannot be initialized or fails unexpectedly.

  • TimeoutError – If the workflow execution times out.