Explanations
Agent Architecture
Moya's architecture is designed to be modular and flexible. Each agent can be configured with different models and tools, allowing for a wide range of applications.
- Agents: The core components that handle user interactions. Agents can be specialized for different tasks, such as responding to queries or performing actions.
- Tools: Utilities that agents can call to perform specific tasks (e.g., memory management, web searches). Tools enhance the capabilities of agents by providing additional functionalities.
- Classifiers: Components that determine which agent should handle a given message. Classifiers analyze user input and route it to the appropriate agent based on predefined criteria.
How Agents Work
Agents in Moya operate by receiving messages, processing them, and generating responses. The flow typically involves:
- Receiving a Message: The agent listens for user input.
- Processing the Message: The agent analyzes the input and determines the appropriate response.
- Generating a Response: The agent uses its configured model to create a reply.
Example of an Agent
from moya.agents.openai_agent import OpenAIAgent, OpenAIAgentConfig
# Set up the agent configuration
agent_config = OpenAIAgentConfig(
system_prompt="You are a helpful AI assistant.",
model_name="gpt-4o",
temperature=0.7,
max_tokens=2000
)
# Create the agent
agent = OpenAIAgent(
agent_name="my_agent",
description="A simple AI assistant",
agent_config=agent_config
)
# Set up the agent
agent.setup()
# Handle a message
response = agent.handle_message("Hello, how can I help you?")
print(response)
Multi-Agent Systems
Moya supports multi-agent systems where multiple specialized agents work together to handle different types of queries. The key components include:
- Agent Registry: Maintains a collection of available agents.
- Classifiers: Route messages to the appropriate agent based on content analysis.
- Orchestrators: Coordinate the flow of messages between users and agents.
Agent Types
Moya supports several types of agents, each with its own capabilities and use cases:
- OpenAI Agents: Use OpenAI's models (like GPT-4o) for generating responses.
- Bedrock Agents: Leverage AWS Bedrock for accessing various foundation models.
- Ollama Agents: Connect to locally hosted models through Ollama for privacy-focused applications.
- Remote Agents: Communicate with external API endpoints for specialized tasks.
- CrewAI Agents: Integrate with CrewAI for collaborative agent workflows.
Memory Management
Moya provides built-in memory management through the MemoryTool, allowing agents to:
- Store conversation history in threads
- Retrieve past messages for context
- Generate summaries of conversations
This memory system enables agents to maintain context across multiple interactions, creating more coherent and contextually relevant responses.
Orchestrators
Orchestrators in Moya manage the flow of messages between users and agents. They handle:
- Message routing to appropriate agents
- Response collection and formatting
- Stream handling for real-time responses
Moya provides different types of orchestrators:
- SimpleOrchestrator: Routes all messages to a single default agent.
- MultiAgentOrchestrator: Uses a classifier to route messages to different specialized agents.
- ReActOrchestrator: Implements the ReAct (Reasoning and Acting) pattern for more complex workflows.
Tool Registry and Tool Calling
The Tool Registry in Moya allows agents to discover and call external tools. This enables agents to:
- Access external APIs and services
- Perform specialized tasks beyond text generation
- Extend their capabilities without modifying the agent code
Tools are registered with the Tool Registry and can be called by agents using the call_tool
method:
# Register a tool
tool_registry.register_tool(memory_tool)
# Call a tool from an agent
agent.call_tool(
tool_name="MemoryTool",
method_name="store_message",
thread_id="thread_1",
sender="user",
content="Hello, how are you?"
)