langgoap.LangSmithTracer#
- class LangSmithTracer(*, client=None, project_name=None, max_search_events=1000, flush_every=1)[source]#
Emit GOAP planning events to LangSmith as a structured run tree.
- Parameters:
client (Any | None) – Optional pre-configured
langsmith.Client. When omitted, a defaultClient()is constructed. Injectable for tests via a mock.project_name (str | None) – Project name override. When omitted, LangSmith uses
LANGCHAIN_PROJECTor its built-in default.max_search_events (int) – Cap on
search_expandevents retained for a single root run (default1000). Beyond the cap a singlesearch_truncatedmarker is appended and further expansions are dropped for that run;search_dead_endevents bypass the cap.flush_every (int) – Number of appended search events that must accumulate before a batched
update_runupload fires (default1). Terminal lifecycle events (on_plan_complete/on_plan_failed/on_goal_achieved) always force a final flush.
The tracer degrades to no-op behaviour and emits a single
logger.warningwhen no API key is configured, so misconfigured environments never break the planner. Everyclientcall is wrapped in atry/exceptthat swallows and logs exceptions — observability must never propagate failures into the GOAP loop.Concurrency note: a single instance holds mutable per-invocation state (the open root run, the search-event buffer, and the in-flight action-run map). All mutations are serialised by an internal
threading.Lockso the tracer is safe to share across the threads thatParallelGoapExecutorand the asyncioaon_*hooks fan out across — concurrenton_action_start/on_action_completepairs are correlated byaction_name. Two distinct top-level graph invocations sharing one tracer is still unsupported: build one tracer per top-level graph call.- __init__(*, client=None, project_name=None, max_search_events=1000, flush_every=1)[source]#
- Parameters:
client (Any | None)
project_name (str | None)
max_search_events (int)
flush_every (int)
- Return type:
None
Methods
__init__(*[, client, project_name, ...])aon_action_complete(result)aon_action_retry(action, attempt, exception, ...)aon_action_start(action, state)aon_goal_achieved(final_state)aon_plan_complete(plan, duration_ms)aon_plan_failed(reason, duration_ms)aon_plan_start(goal, state, strategy_name)aon_replan(reason, new_plan[, duration_ms])aon_search_complete(nodes_explored, ...)aon_search_dead_end(reason, detail)aon_search_expand(node_id, state, g, h, f, ...)aon_sensor_complete(sensor_name, updates)aon_strategy_chosen(strategy_name)on_action_complete(result)on_action_retry(action, attempt, exception, ...)Record an in-executor retry as metadata on the action's run.
on_action_start(action, state)on_goal_achieved(final_state)on_plan_complete(plan, duration_ms)on_plan_failed(reason, duration_ms)on_plan_start(goal, state, strategy_name)on_replan(reason, new_plan[, duration_ms])on_search_complete(nodes_explored, ...)on_search_dead_end(reason, detail)on_search_expand(node_id, state, g, h, f, ...)on_sensor_complete(sensor_name, updates)Record a sensor completion event as metadata on the root LangSmith run.
on_strategy_chosen(strategy_name)Record the routed strategy as metadata on the active root run.