Hooks
React agents hooks
The react-agents
library provides a few hooks to help you interact with your agent.
Agent hooks
useAgent()
Returns the current Agent
context.
useConversations()
Returns the array of conversations the Agent
is currently participating in.
useConversation()
Returns the current Conversation
.
Must be used from the child of a <Conversation>
.
Metadata Hooks
useName()
Returns the agent's name, prioritizing the registry name over the agent's default name.
usePersonality()
Returns the agent's personality/bio, prioritizing the registry personality over the agent's default bio.
Message Hooks
useCachedMessages()
Returns cached messages for the current conversation, with optional filtering. Automatically handles loading and updates.
useNumMessages()
Returns the total number of cached messages in the current conversation.
Environment Hooks
useEnvironment()
Returns the current environment: 'development'
or 'production'
.
This can be used to determine if the agent is running in a development or deployed server environment.
useAuthToken()
Returns the current authentication token.
Generally, you should not need to use this.
Warning: Do not put this token into the prompt context or use it anywhere it might be seen by a user, as it can be used to take over the agent.
Utility Hooks
useKv()
Returns the key-value storage interface from the AppContext.
useTts(opts?)
Returns a memoized text-to-speech interface with optional voice endpoint and sample rate configuration.