Documentation
¶
Overview ¶
Package callbacks provides callback handler implementations for observability, tracing, and debugging of LangChain executions.
Index ¶
- type LangSmithHandler
- func (h *LangSmithHandler) Close(ctx context.Context) error
- func (h *LangSmithHandler) Flush(ctx context.Context) error
- func (h *LangSmithHandler) OnChainEnd(_ context.Context, outputs map[string]any, runID string)
- func (h *LangSmithHandler) OnChainError(_ context.Context, err error, runID string)
- func (h *LangSmithHandler) OnChainStart(_ context.Context, inputs map[string]any, runID string, parentRunID string, ...)
- func (h *LangSmithHandler) OnChatModelStart(_ context.Context, _ []core.Message, runID string, parentRunID string, ...)
- func (h *LangSmithHandler) OnLLMEnd(_ context.Context, output *core.LLMResult, runID string)
- func (h *LangSmithHandler) OnLLMError(_ context.Context, err error, runID string)
- func (h *LangSmithHandler) OnLLMStart(_ context.Context, prompts []string, runID string, parentRunID string, ...)
- func (h *LangSmithHandler) OnRetrieverEnd(_ context.Context, documents []*core.Document, runID string)
- func (h *LangSmithHandler) OnRetrieverError(_ context.Context, err error, runID string)
- func (h *LangSmithHandler) OnRetrieverStart(_ context.Context, query string, runID string, parentRunID string)
- func (h *LangSmithHandler) OnToolEnd(_ context.Context, output string, runID string)
- func (h *LangSmithHandler) OnToolError(_ context.Context, err error, runID string)
- func (h *LangSmithHandler) OnToolStart(_ context.Context, toolName string, input string, runID string, ...)
- type Manager
- func (m *Manager) AllHandlers() []core.CallbackHandler
- func (m *Manager) GetChild(tag string) *Manager
- func (m *Manager) OnAgentAction(ctx context.Context, action core.AgentActionData, runID string)
- func (m *Manager) OnAgentFinish(ctx context.Context, finish core.AgentFinishData, runID string)
- func (m *Manager) OnChainEnd(ctx context.Context, outputs map[string]any, runID string)
- func (m *Manager) OnChainError(ctx context.Context, err error, runID string)
- func (m *Manager) OnChainStart(ctx context.Context, inputs map[string]any, runID string, parentRunID string, ...)
- func (m *Manager) OnChatModelStart(ctx context.Context, messages []core.Message, runID string, parentRunID string, ...)
- func (m *Manager) OnLLMEnd(ctx context.Context, output *core.LLMResult, runID string)
- func (m *Manager) OnLLMError(ctx context.Context, err error, runID string)
- func (m *Manager) OnLLMNewToken(ctx context.Context, token string, runID string)
- func (m *Manager) OnLLMStart(ctx context.Context, prompts []string, runID string, parentRunID string, ...)
- func (m *Manager) OnRetrieverEnd(ctx context.Context, documents []*core.Document, runID string)
- func (m *Manager) OnRetrieverError(ctx context.Context, err error, runID string)
- func (m *Manager) OnRetrieverStart(ctx context.Context, query string, runID string, parentRunID string)
- func (m *Manager) OnText(ctx context.Context, text string, runID string)
- func (m *Manager) OnToolEnd(ctx context.Context, output string, runID string)
- func (m *Manager) OnToolError(ctx context.Context, err error, runID string)
- func (m *Manager) OnToolStart(ctx context.Context, toolName string, input string, runID string, ...)
- func (m *Manager) WithInheritableHandlers(handlers ...core.CallbackHandler) *Manager
- func (m *Manager) WithMetadata(metadata map[string]any) *Manager
- func (m *Manager) WithParentRunID(id string) *Manager
- func (m *Manager) WithTags(tags ...string) *Manager
- type StdoutHandler
- func (h *StdoutHandler) OnAgentAction(_ context.Context, action core.AgentActionData, _ string)
- func (h *StdoutHandler) OnAgentFinish(_ context.Context, finish core.AgentFinishData, _ string)
- func (h *StdoutHandler) OnChainEnd(_ context.Context, outputs map[string]any, _ string)
- func (h *StdoutHandler) OnChainError(_ context.Context, err error, _ string)
- func (h *StdoutHandler) OnChainStart(_ context.Context, inputs map[string]any, runID string, _ string, ...)
- func (h *StdoutHandler) OnChatModelStart(_ context.Context, messages []core.Message, _ string, _ string, ...)
- func (h *StdoutHandler) OnLLMEnd(_ context.Context, output *core.LLMResult, _ string)
- func (h *StdoutHandler) OnLLMError(_ context.Context, err error, _ string)
- func (h *StdoutHandler) OnLLMNewToken(_ context.Context, token string, _ string)
- func (h *StdoutHandler) OnLLMStart(_ context.Context, prompts []string, _ string, _ string, _ map[string]any)
- func (h *StdoutHandler) OnRetrieverEnd(_ context.Context, documents []*core.Document, _ string)
- func (h *StdoutHandler) OnRetrieverStart(_ context.Context, query string, _ string, _ string)
- func (h *StdoutHandler) OnText(_ context.Context, text string, _ string)
- func (h *StdoutHandler) OnToolEnd(_ context.Context, output string, _ string)
- func (h *StdoutHandler) OnToolError(_ context.Context, err error, _ string)
- func (h *StdoutHandler) OnToolStart(_ context.Context, toolName string, input string, _ string, _ string)
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 (*LangSmithHandler) OnChainError ¶
func (h *LangSmithHandler) OnChainError(_ context.Context, err error, runID string)
func (*LangSmithHandler) OnChainStart ¶
func (*LangSmithHandler) OnChatModelStart ¶
func (*LangSmithHandler) OnLLMError ¶
func (h *LangSmithHandler) OnLLMError(_ context.Context, err error, runID string)
func (*LangSmithHandler) OnLLMStart ¶
func (*LangSmithHandler) OnRetrieverEnd ¶
func (*LangSmithHandler) OnRetrieverError ¶
func (h *LangSmithHandler) OnRetrieverError(_ context.Context, err error, runID string)
func (*LangSmithHandler) OnRetrieverStart ¶
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 ¶
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) OnAgentAction ¶
OnAgentAction dispatches to all handlers.
func (*Manager) OnAgentFinish ¶
OnAgentFinish dispatches to all handlers.
func (*Manager) OnChainEnd ¶
OnChainEnd dispatches to all handlers.
func (*Manager) OnChainError ¶
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) OnLLMError ¶
OnLLMError dispatches to all handlers.
func (*Manager) OnLLMNewToken ¶
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 ¶
OnRetrieverEnd dispatches to all handlers.
func (*Manager) OnRetrieverError ¶
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) OnToolError ¶
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 ¶
WithMetadata sets metadata for all dispatched events.
func (*Manager) WithParentRunID ¶
WithParentRunID sets the parent run ID.
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 (*StdoutHandler) OnChainError ¶
func (h *StdoutHandler) OnChainError(_ context.Context, err error, _ string)
func (*StdoutHandler) OnChainStart ¶
func (*StdoutHandler) OnChatModelStart ¶
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 (*StdoutHandler) OnRetrieverEnd ¶
func (*StdoutHandler) OnRetrieverStart ¶
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)