Skip to content

Access to Chat History in HooksΒ #346

@gabriansa

Description

@gabriansa

Description

Add ability to access and modify the chat history through RunHooks/AgentHooks while the agent is running. This would allow adding custom messages or modifying the conversation context during execution.

Use Case

  • Injecting context-specific messages during agent execution
  • Modifying conversation history in response to specific events

Proposed Dummy Implementation

  1. Add message history to RunContextWrapper
  2. Expose methods to add/modify messages through hooks:
class SomeHooks(AgentHooks[SomeContext]):    
    async def on_tool_end(
        self,
        context: RunContextWrapper[SomeContext],
        agent: Any,
        tool: Tool,
    ) -> None:
        agent.add_message({"role": "user", "content": "some text"})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions