-
Notifications
You must be signed in to change notification settings - Fork 3
Context Injection
David-Andrew Samson edited this page Jun 22, 2023
·
9 revisions
While interacting with the LLM react agent, it is possible to inject context messages into the chat history. Context messages are very flexible and can be used in a number of different ways:
- providing the agent with information about the current state of a tool
- temporarily including chat history that can be deleted later to save context length
- (etc/todo)
Context can be created by calling one of the add_context methods on the agent
agent = ReActAgent(...)
# add permanent context
id = agent.add_context("some context message")
# add timed context
n = 5
id = agent.add_context("some message that will be deleted after n steps", lifetime=n)Timed context messages are automatically deleted from the chat after the specified number of steps (default of 1), or you can manually delete them before the time expires
Context can be removed via the clear_context function given the message's id
agent.clear_context(id)Additionally, all context can be cleared with clear_all_context
agent.clear_all_context()(todo)