Skip to content

ToolContext

Context passed to tool handlers during agent loop execution. Provides access to the agent configuration, current conversation state, and arbitrary metadata for tool implementations that need broader context.

---
title: ToolContext
config:
  look: handDrawn
  theme: colorful
  class:
    hideEmptyMembersBox: true
---
classDiagram
    class ToolContext {
        +Message[] messages
        +dictionary metadata
    }
    class Message {
        +string role
        +ContentPart[] parts
        +dictionary metadata
        +toTextContent() unknown [async-capable]
        +text() string [async-capable]
    }
    ToolContext *-- Message
metadata:
userId: user-123
NameTypeDescription
messagesMessage[]The current conversation messages at the point of tool invocation
metadatadictionaryOptional metadata for tool-specific context (e.g., user session info)

The following types are composed within ToolContext: