callbacks

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package callbacks provides callback handler implementations for observability, tracing, and debugging of LangChain executions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LangSmithHandler

type LangSmithHandler struct {
	core.BaseCallbackHandler
	// contains filtered or unexported fields
}

LangSmithHandler sends tracing data to LangSmith for observability.

func NewLangSmithHandler

func NewLangSmithHandler(project string) *LangSmithHandler

NewLangSmithHandler creates a new LangSmith tracing handler. It reads LANGCHAIN_API_KEY and LANGCHAIN_ENDPOINT from environment variables.

func (*LangSmithHandler) Close

func (h *LangSmithHandler) Close(ctx context.Context) error

Close prevents new events from being queued and flushes pending work.

func (*LangSmithHandler) Flush

func (h *LangSmithHandler) Flush(ctx context.Context) error

Flush waits for all queued HTTP work to complete.

func (*LangSmithHandler) OnChainEnd

func (h *LangSmithHandler) OnChainEnd(_ context.Context, outputs map[string]any, runID string)

func (*LangSmithHandler) OnChainError

func (h *LangSmithHandler) OnChainError(_ context.Context, err error, runID string)

func (*LangSmithHandler) OnChainStart

func (h *LangSmithHandler) OnChainStart(_ context.Context, inputs map[string]any, runID string, parentRunID string, extras map[string]any)

func (*LangSmithHandler) OnChatModelStart

func (h *LangSmithHandler) OnChatModelStart(_ context.Context, _ []core.Message, runID string, parentRunID string, extras map[string]any)

func (*LangSmithHandler) OnLLMEnd

func (h *LangSmithHandler) OnLLMEnd(_ context.Context, output *core.LLMResult, runID string)

func (*LangSmithHandler) OnLLMError

func (h *LangSmithHandler) OnLLMError(_ context.Context, err error, runID string)

func (*LangSmithHandler) OnLLMStart

func (h *LangSmithHandler) OnLLMStart(_ context.Context, prompts []string, runID string, parentRunID string, extras map[string]any)

func (*LangSmithHandler) OnRetrieverEnd

func (h *LangSmithHandler) OnRetrieverEnd(_ context.Context, documents []*core.Document, runID string)

func (*LangSmithHandler) OnRetrieverError

func (h *LangSmithHandler) OnRetrieverError(_ context.Context, err error, runID string)

func (*LangSmithHandler) OnRetrieverStart

func (h *LangSmithHandler) OnRetrieverStart(_ context.Context, query string, runID string, parentRunID string)

func (*LangSmithHandler) OnToolEnd

func (h *LangSmithHandler) OnToolEnd(_ context.Context, output string, runID string)

func (*LangSmithHandler) OnToolError

func (h *LangSmithHandler) OnToolError(_ context.Context, err error, runID string)

func (*LangSmithHandler) OnToolStart

func (h *LangSmithHandler) OnToolStart(_ context.Context, toolName string, input string, runID string, parentRunID string)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager coordinates multiple callback handlers, dispatching events to all of them.

func NewManager

func NewManager(handlers ...core.CallbackHandler) *Manager

NewManager creates a new callback Manager.

func (*Manager) AllHandlers

func (m *Manager) AllHandlers() []core.CallbackHandler

AllHandlers returns all registered handlers.

func (*Manager) GetChild

func (m *Manager) GetChild(tag string) *Manager

GetChild creates a child manager that inherits inheritable handlers.

func (*Manager) OnAgentAction

func (m *Manager) OnAgentAction(ctx context.Context, action core.AgentActionData, runID string)

OnAgentAction dispatches to all handlers.

func (*Manager) OnAgentFinish

func (m *Manager) OnAgentFinish(ctx context.Context, finish core.AgentFinishData, runID string)

OnAgentFinish dispatches to all handlers.

func (*Manager) OnChainEnd

func (m *Manager) OnChainEnd(ctx context.Context, outputs map[string]any, runID string)

OnChainEnd dispatches to all handlers.

func (*Manager) OnChainError

func (m *Manager) OnChainError(ctx context.Context, err error, runID string)

OnChainError dispatches to all handlers.

func (*Manager) OnChainStart

func (m *Manager) OnChainStart(ctx context.Context, inputs map[string]any, runID string, parentRunID string, extras map[string]any)

OnChainStart dispatches to all handlers.

func (*Manager) OnChatModelStart

func (m *Manager) OnChatModelStart(ctx context.Context, messages []core.Message, runID string, parentRunID string, extras map[string]any)

OnChatModelStart dispatches to all handlers.

func (*Manager) OnLLMEnd

func (m *Manager) OnLLMEnd(ctx context.Context, output *core.LLMResult, runID string)

OnLLMEnd dispatches to all handlers.

func (*Manager) OnLLMError

func (m *Manager) OnLLMError(ctx context.Context, err error, runID string)

OnLLMError dispatches to all handlers.

func (*Manager) OnLLMNewToken

func (m *Manager) OnLLMNewToken(ctx context.Context, token string, runID string)

OnLLMNewToken dispatches to all handlers.

func (*Manager) OnLLMStart

func (m *Manager) OnLLMStart(ctx context.Context, prompts []string, runID string, parentRunID string, extras map[string]any)

OnLLMStart dispatches to all handlers.

func (*Manager) OnRetrieverEnd

func (m *Manager) OnRetrieverEnd(ctx context.Context, documents []*core.Document, runID string)

OnRetrieverEnd dispatches to all handlers.

func (*Manager) OnRetrieverError

func (m *Manager) OnRetrieverError(ctx context.Context, err error, runID string)

OnRetrieverError dispatches to all handlers.

func (*Manager) OnRetrieverStart

func (m *Manager) OnRetrieverStart(ctx context.Context, query string, runID string, parentRunID string)

OnRetrieverStart dispatches to all handlers.

func (*Manager) OnText

func (m *Manager) OnText(ctx context.Context, text string, runID string)

OnText dispatches to all handlers.

func (*Manager) OnToolEnd

func (m *Manager) OnToolEnd(ctx context.Context, output string, runID string)

OnToolEnd dispatches to all handlers.

func (*Manager) OnToolError

func (m *Manager) OnToolError(ctx context.Context, err error, runID string)

OnToolError dispatches to all handlers.

func (*Manager) OnToolStart

func (m *Manager) OnToolStart(ctx context.Context, toolName string, input string, runID string, parentRunID string)

OnToolStart dispatches to all handlers.

func (*Manager) WithInheritableHandlers

func (m *Manager) WithInheritableHandlers(handlers ...core.CallbackHandler) *Manager

WithInheritableHandlers adds handlers that will be inherited by child managers.

func (*Manager) WithMetadata

func (m *Manager) WithMetadata(metadata map[string]any) *Manager

WithMetadata sets metadata for all dispatched events.

func (*Manager) WithParentRunID

func (m *Manager) WithParentRunID(id string) *Manager

WithParentRunID sets the parent run ID.

func (*Manager) WithTags

func (m *Manager) WithTags(tags ...string) *Manager

WithTags sets tags for all dispatched events.

type StdoutHandler

type StdoutHandler struct {
	core.BaseCallbackHandler
	// Color enables ANSI color output.
	Color bool
}

StdoutHandler prints callback events to stdout for debugging.

func NewStdoutHandler

func NewStdoutHandler() *StdoutHandler

NewStdoutHandler creates a new StdoutHandler.

func (*StdoutHandler) OnAgentAction

func (h *StdoutHandler) OnAgentAction(_ context.Context, action core.AgentActionData, _ string)

func (*StdoutHandler) OnAgentFinish

func (h *StdoutHandler) OnAgentFinish(_ context.Context, finish core.AgentFinishData, _ string)

func (*StdoutHandler) OnChainEnd

func (h *StdoutHandler) OnChainEnd(_ context.Context, outputs map[string]any, _ string)

func (*StdoutHandler) OnChainError

func (h *StdoutHandler) OnChainError(_ context.Context, err error, _ string)

func (*StdoutHandler) OnChainStart

func (h *StdoutHandler) OnChainStart(_ context.Context, inputs map[string]any, runID string, _ string, extras map[string]any)

func (*StdoutHandler) OnChatModelStart

func (h *StdoutHandler) OnChatModelStart(_ context.Context, messages []core.Message, _ string, _ string, _ map[string]any)

func (*StdoutHandler) OnLLMEnd

func (h *StdoutHandler) OnLLMEnd(_ context.Context, output *core.LLMResult, _ string)

func (*StdoutHandler) OnLLMError

func (h *StdoutHandler) OnLLMError(_ context.Context, err error, _ string)

func (*StdoutHandler) OnLLMNewToken

func (h *StdoutHandler) OnLLMNewToken(_ context.Context, token string, _ string)

func (*StdoutHandler) OnLLMStart

func (h *StdoutHandler) OnLLMStart(_ context.Context, prompts []string, _ string, _ string, _ map[string]any)

func (*StdoutHandler) OnRetrieverEnd

func (h *StdoutHandler) OnRetrieverEnd(_ context.Context, documents []*core.Document, _ string)

func (*StdoutHandler) OnRetrieverStart

func (h *StdoutHandler) OnRetrieverStart(_ context.Context, query string, _ string, _ string)

func (*StdoutHandler) OnText

func (h *StdoutHandler) OnText(_ context.Context, text string, _ string)

func (*StdoutHandler) OnToolEnd

func (h *StdoutHandler) OnToolEnd(_ context.Context, output string, _ string)

func (*StdoutHandler) OnToolError

func (h *StdoutHandler) OnToolError(_ context.Context, err error, _ string)

func (*StdoutHandler) OnToolStart

func (h *StdoutHandler) OnToolStart(_ context.Context, toolName string, input string, _ string, _ string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL