<Agent>
Learn how to use the Agent Component to lay out the foundation of your Agent.
The Agent component serves as a high-level wrapper component that provides the core infrastructure for AI agent functionality in a React application. It acts as a container that:
- Establishes the communication context for AI interactions
- Manages the state and lifecycle of AI agent operations
- Provides necessary context and configuration to child components
- Enables action handling and event processing for nested agent functionalities
Import
Usage
The Agent class has represents a currently running agent. It corresponds 1:1 to an <Agent> tag in your code.
You do not construct the Agent class yourself. It is created for you when your <Agent> gets rendered by the runtime.
Reference
The Agent class exposes helpful functions to help build your Agent. When you have a handle to your agent, you can access its methods.
useAgent hook
Any component nested within an <Agent> can call the useAgent hook to get a handle to the underlying Agent class. See reference
handler callback:
Each handler in your agent (such as <Action handler={(event) => {/* ... */}}> or <Perception handler={(event) => {/* ... */}}>) has an agent key on the event.data. You can use this for convenient access to the currently running agent. e.g.
useRef hook
Every <Agent> has an internal ref that resolves to the Agent instance. You can access it the usual way using React's useRef:
Source code
You can see the code for the Agent Component in our GitHub.
