oc_chat
Loading...
Searching...
No Matches
oc_chat.tools.planner Namespace Reference

Classes

class  Step
class  Plan

Functions

"tuple[list[str] | None, str | None]" _coerce_steps (object steps)
dict create_plan (str goal, list steps)
dict get_status ()
dict mark_step (int step_index, str status, str result="")
dict stop_plan ()

Variables

 _active_plan = None
bool _stopped = False
tuple _STEP_TEXT_KEYS = ("description", "step", "title", "text", "name", "task")
dict TOOLS
list SCHEMAS

Detailed Description

Multi-step task planner for agentic goal execution.

Purpose
-------
Process-singleton plan state that the model uses to break a complex
goal into discrete steps and track progress across ReAct iterations.
The model calls :func:`create_plan` to set up a plan, :func:`mark_step`
as each step completes, :func:`get_status` for progress, and
:func:`stop_plan` to halt execution.

Responsibilities
----------------
- :class:`Step` / :class:`Plan` — dataclasses describing a single
  step (description, status, result) and the active plan (goal,
  steps, completion check).
- :func:`create_plan` — start a new plan; replaces any existing one.
- :func:`mark_step` — transition a step to ``done`` / ``failed`` with
  an optional result string.
- :func:`get_status` — return the current plan as a dict.
- :func:`stop_plan` — clear active plan state and set the stop flag.

Diagnostics
-----------
Domain: OC_CHAT.TOOLS
Levels:
    L2 — lifecycle events
    L3 — semantic details
    L4 — deep tracing

Contracts
---------
- Module-level ``_active_plan`` and ``_stopped`` are process-singleton
  state — only one plan is active at a time per REPL.
- ``create_plan`` overwrites any existing plan without warning.
- ``mark_step`` validates the step index; out-of-range indices return
  an error dict rather than raising.
- ``stop_plan`` is idempotent — calling it twice has no extra effect.

Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)

See Also
--------
oc_chat/docs/conventions/CONTRACTS.md §8 Plan / Step — owner of the planner
dataclasses; §3 Tool registry contract; §4 Tool return-value conventions.

Function Documentation

◆ _coerce_steps()

"tuple[list[str] | None, str | None]" oc_chat.tools.planner._coerce_steps ( object steps)
protected
Coerce a model-supplied *steps* value into a ``list[str]``, or return an error.

F28: ``create_plan`` used to ``len(steps)`` / iterate ``steps`` blindly, so a
``None`` raised ``TypeError`` (invisible crash) and a bare STRING was silently
char-split into one step per character. This tolerates the shapes the model
actually sends — a list of dicts (``{'description'|'step'|'title'|...: ...}``),
non-string scalars (stringified) — and hard-rejects only the crash/corruption
shapes (``None`` and a bare string). An empty list is allowed (an empty plan is
a valid, supported state).

Returns ``(steps_list, None)`` on success or ``(None, error_message)``.

Definition at line 97 of file planner.py.

Here is the caller graph for this function:

◆ create_plan()

dict oc_chat.tools.planner.create_plan ( str goal,
list steps )
Create a new plan with a list of step descriptions.

Validates and coerces the model-supplied arguments (F28) so a malformed call
returns a structured ``{"error": ...}`` the model can act on — it never raises
(an invisible crash) or silently char-splits a bare string.

Definition at line 147 of file planner.py.

Here is the call graph for this function:

◆ get_status()

dict oc_chat.tools.planner.get_status ( )
Return the current plan status including all step statuses.

Definition at line 178 of file planner.py.

◆ mark_step()

dict oc_chat.tools.planner.mark_step ( int step_index,
str status,
str result = "" )
Update the status of a plan step.

*status* must be one of ``pending``, ``running``, ``done``, ``failed``.

Definition at line 193 of file planner.py.

◆ stop_plan()

dict oc_chat.tools.planner.stop_plan ( )
Halt the active plan.

Call this when the goal is complete, impossible, or the user has
requested a stop.

Definition at line 210 of file planner.py.

Variable Documentation

◆ _active_plan

oc_chat.tools.planner._active_plan = None
protected

Definition at line 58 of file planner.py.

◆ _STEP_TEXT_KEYS

tuple oc_chat.tools.planner._STEP_TEXT_KEYS = ("description", "step", "title", "text", "name", "task")
protected

Definition at line 94 of file planner.py.

◆ _stopped

bool oc_chat.tools.planner._stopped = False
protected

Definition at line 59 of file planner.py.

◆ SCHEMAS

list oc_chat.tools.planner.SCHEMAS

Definition at line 228 of file planner.py.

◆ TOOLS

dict oc_chat.tools.planner.TOOLS
Initial value:
1= {
2 "create_plan": create_plan,
3 "get_status": get_status,
4 "mark_step": mark_step,
5 "stop_plan": stop_plan,
6}

Definition at line 221 of file planner.py.