langgoap.LangSmithTracer

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 default Client() is constructed. Injectable for tests via a mock.

  • project_name (str | None) – Project name override. When omitted, LangSmith uses LANGCHAIN_PROJECT or its built-in default.

  • max_search_events (int) – Cap on search_expand events retained for a single root run (default 1000). Beyond the cap a single search_truncated marker is appended and further expansions are dropped for that run; search_dead_end events bypass the cap.

  • flush_every (int) – Number of appended search events that must accumulate before a batched update_run upload fires (default 1). 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.warning when no API key is configured, so misconfigured environments never break the planner. Every client call is wrapped in a try/except that 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.Lock so the tracer is safe to share across the threads that ParallelGoapExecutor and the asyncio aon_* hooks fan out across — concurrent on_action_start / on_action_complete pairs are correlated by action_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.