Agents¶
Overview¶
Agents in RAI are modular components that encapsulate specific functionalities and behaviors. They follow a consistent interface defined by the BaseAgent
class and can be combined to create complex robotic systems.
BaseAgent¶
BaseAgent
is the abstract base class for all agent implementations in the RAI framework. It defines the minimal interface that all agents must implement while providing common functionality like logging.
Class Definition¶
BaseAgent class definition
rai.agents.base.BaseAgent
¶
Bases: ABC
Source code in rai/agents/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
__init__()
¶
Initializes a new agent instance and sets up logging with the class name.
Source code in rai/agents/base.py
20 21 22 |
|
run()
abstractmethod
¶
Starts the agent's main execution loop. In some cases, concrete run implementation may not be needed. In that case use pass as a placeholder.
Source code in rai/agents/base.py
24 25 26 27 28 29 |
|
stop()
abstractmethod
¶
Gracefully terminates the agent's execution and cleans up resources.
Source code in rai/agents/base.py
31 32 33 34 |
|
Purpose¶
The BaseAgent
class serves as the cornerstone of RAI's agent architecture, establishing a uniform interface for various agent implementations. This enables:
- Consistent lifecycle management (starting/stopping)
- Standardized logging mechanisms
- Interoperability between different agent types
- Integration with management utilities like
AgentRunner
Best Practices¶
- Resource Management: Always clean up resources in the
stop()
method - Thread Safety: Use locks for shared resources when implementing multi-threaded agents
- Error Handling: Implement proper exception handling in long-running agent threads
- Logging: Use the provided
self.logger
for consistent logging - Graceful Shutdown: Handle interruptions and cleanup properly
Architecture¶
In the RAI framework, agents typically interact with:
- Connectors: For communication (ROS2, audio devices, etc.)
- Aggregators: For processing and summarizing input data
- Models: For AI capabilities (LLMs, vision models, speech recognition)
- Tools: For implementing specific actions an agent can take
See Also¶
- Aggregators: For more information on the different types of aggregators in RAI
- Connectors: For more information on the different types of connectors in RAI
- Langchain Integration: For more information on the LangChain integration within RAI
- Multimodal messages: For more information on the multimodal LangChain messages in RAI
- Runners: For more information on the different types of runners in RAI