All pages
Powered by GitBook
1 of 1

Loading...

State-Based Architecture

A context graph is a structured topological field of interconnected states that guides agent behavior and decision-making. Context graphs implement a hierarchical state machine (HSM) architecture, where states are organized in a structured hierarchy that enables efficient organization of complex problem spaces.

State Types

Each state type serves a specific purpose in managing conversation flow and agent behavior.

Context Graphs orchestrate agent behavior through a structured hierarchy of states:

  • Decision States: Choose optimal actions based on real-time data and objectives, drawing on the integrated Memory-Knowledge-Reasoning (M-K-R) system.

  • Action States: Execute defined tasks with clear rules and constraints, powered by the current M-K-R context.

  • Reflection States: Allow introspection and strategic reasoning. These are critical junctures in the M-K-R cycle, where the agent might re-evaluate its understanding (Knowledge), recontextualize Memory, and refine its Reasoning pathways before proceeding.

State Reference

State type
Purpose
Typical use

Designing a State

Side-Effect states exist to produce effects outside the conversation loop. They hand off control to Actions and other tooling, ensuring that every external operation is versioned and auditable without overloading Action states with non-dialog responsibilities.

Each state definition should answer five questions before it ships to production:

  1. Objective – What outcome must be true before the state can exit?

  2. Guidance – Which ordered actions or prompts keep the model on the intended path?

  3. Boundaries – Which behaviors are forbidden, especially for safety or compliance?

  4. Exit criteria – What explicit signals trigger each transition, and which state should follow?

In the API schema this maps to action_tool_call_specs, exit_condition_tool_call_specs, and the skip_active_memory_retrieval flag for each state.

Action State Implementation Example

Each state type has its unique set of structured parameters and implementation best practices. For example, see below for a more detailed summary of the Action State.

Action State

Action states create engagement fields where the agent directly interacts with clients. They require careful design with balanced constraints to create optimal movement paths.

Required Parameters

  • type: Must be "action"

  • objective: Clear statement of the state's goal

  • actions: Ordered list of client-facing interaction steps

Optional Parameters

  • action_tool_call_specs: Optional tool calls the agent may use while executing actions

  • exit_condition_tool_call_specs: Tool calls available when evaluating exit conditions

  • skip_active_memory_retrieval: Set to true when the state should not trigger active memory retrieval on entry

Example

Reasoning States and Abstract Topology

Reasoning states (which include Decision and Reflection states) play a critical role in the traversal of context graphs, acting as key nodes in the integrated Memory-Knowledge-Reasoning (M-K-R) process. They impact traversal by providing a local and global view of the problem space via an abstract topology. This abstract topological view:

  1. Prevents Loops: Avoids repetitive cycles of states that don't make progress toward goals

  2. Prevents Bad Traversals: Eliminates paths that don't properly consider the more global problem space view

  3. Optimizes Transitions: Prevents both premature and late transitions to adjacent problem spaces even without perfect exit conditions

The abstract topology effectively provides a "map" of the entire problem space, allowing the agent to make informed decisions about where to go next based on both immediate context and the overall structure of the problem. This is similar to how a human expert would consider the current details of a situation and their broader understanding of the entire domain when making decisions.

Here's a simplified example of an abstract topology for a medical check-in flow:

This abstract topology provides a concise map of the problem space, showing key states and transitions. With this global view, the agent can make informed decisions about state traversal, ensuring that the conversation follows a coherent and purposeful path while avoiding problematic patterns like loops or premature transitions.

Multi-State Traversal: The Hidden Journey Between Action States

A fundamental aspect of context graphs is that agents can traverse multiple states internally before responding to users. The core guarantee: agents always start and end on action states, but the journey between them can involve sophisticated internal processing that remains invisible to users.

Core Traversal Principles

  1. Action State Guarantee: Agents always start and end on action states

  2. Arbitrary Steps: Agents can take an arbitrary number of internal steps before responding

  3. Quantum Composition: Each state can be composed of smaller quantas of actions (like tool calls)

  4. Internal Processing: Between action states, agents traverse internal states for reasoning, memory operations, and decision-making

Quantum Patterns

Each interaction is composed of quantas of patterns - fundamental units of state transitions:

Basic Quantas:

  • action → action - Direct response

  • action → decision → reflection → action - Thoughtful evaluation

  • action → action → action - Multi-step direct engagement

Complex Quantas:

Traversal Patterns

Each interaction follows patterns like:

  • [A] action → [A] action - Direct transition

  • [A] action → [D] decision → [R] reflection → [A] action - Thoughtful evaluation

  • [A] action → [R] reflection → [D] decision → [A] action - Analysis before routing

These patterns represent "quanta" of agent behavior - fundamental units of processing that compose into complex interactions.

Three Levels of Navigation Intelligence

Agents navigate using three complementary information levels that provide both global and local perspectives:

  1. Conceptual Level (Description)

    • The "why" - service philosophy and methodology

    • Sparse, conceptual global view of the entire service

    • Provides understanding of overall purpose and approach

This multi-resolution approach is powerful because it gives agents both the "forest and the trees" - they can see the big picture through sparse conceptual and structural views while having dense, detailed guidance for local execution. This enables intelligent navigation that balances global strategy with local precision.

Example: Hidden Therapeutic Processing

User: "I feel like I'm not making progress in therapy"

Internal traversal:

  1. [A] get_therapeutic_agreement_get_focus - Acknowledges concern about therapy progress

  2. [C] recall - Retrieves past session goals, breakthroughs, and patterns

  3. [R] reflect_on_therapeutic_agreement - Analyzes the gap between expectations and experience

User experience: The therapist responds with deep understanding of their therapeutic journey, acknowledging past work while exploring their current feelings, all without revealing the complex internal analysis.

Navigation Strategies

For Non-Intuitive Transitions: When jumps might surprise users

  • Highly detailed exit conditions

  • Explicit descriptions of when/why transitions occur

  • Clear documentation of edge cases

For Intuitive Navigation: When flow should feel natural

  • Rich conceptual descriptions

  • Lighter transition guidelines

  • Agent discretion based on context

Implementation Considerations

  1. Context Density Calibration (Entropy Control in Practice):

    • High-density (Low Entropy): "Verify all required regulatory compliance elements while maintaining strict protocol adherence"

    • Medium-density (Medium Entropy): "Engage the client on their current query while handling natural topic changes within conversation flow"

Recall States: Allow explicit integration with user memory to increase personalization. These states directly tap into the Memory component of M-K-R, bringing historical context to bear on current Knowledge application and Reasoning.

  • Annotation States: Clarify and segment complex interactions.

  • Side-Effect States: Touch points for external system interaction, enabling Actions.

  • Annotation

    Tag context for downstream processing

    Segment transcripts, mark compliance events

    Side-Effect (Action Gateway)

    Stage and trigger external systems or tools without user-facing output

    Schedule follow-ups, call APIs, write structured logs

    Tooling & memory configuration – Which tool calls are exposed in this state and should active memory retrieval be skipped?

    intra_state_navigation_guidelines: Rules for action sequencing and exit condition selection
  • action_guidelines: Behavioral rules for the agent

  • boundary_constraints: Limitations on agent behavior

  • exit_conditions: List of conditions that trigger state transitions

  • Hidden Complexity: Users only see the action state responses, not the internal journey

  • Response Guarantee: The only guarantee is that the agent responds in an action state

  • [A] action → [C] recall → [D] decision → [A] action - Memory-informed decision

    Rich, detailed description of how the service should work

  • Structural Level (Abstract Topology)

    • The "what" - map of possible state transitions

    • Zoomed-out global view showing all states and connections

    • Enables seeing multiple steps ahead in the problem space

    • Allows strategic path planning across the entire graph

  • Local Level (State Guidelines)

    • The "how" - specific execution instructions

    • Dense, high-resolution local view of current state

    • Detailed objectives, actions, and boundaries

    • Precise exit conditions that determine next transitions

  • [D] assess_focus_significance - Evaluates if this reflects deeper therapeutic resistance
  • [A] get_therapeutic_agreement_get_meaningfulness - Explores what progress means to them

  • Low-density (High Entropy): "Create space for open exploration of possibilities without excessive structure"

    This density calibration demonstrates strategic entropy management—applying tight constraints when precision matters (compliance), balanced guidance for operational workflows, and minimal constraints for creative exploration.

  • Action Sequencing:

    • Define action sequences that create natural progressive movement

    • Balance between prescriptive steps and open exploration

    • Example from healthcare implementation: "Address user queries → Ask personalized follow-up questions → Handle topic changes → Track conversation context"

  • Navigation Guidelines Implementation:

    • Define intra-state movement behaviors

    • Example: "When client introduces a new topic, handle it within this state rather than triggering a state change"

    • Implementation shows how agent navigates within a single region of the field

  • Exit Condition Design:

    • Create clear, detectable boundaries for state transitions

    • Support both simple state transitions and cross-graph navigation

    • Include safety exits for unexpected situations

  • Decision

    Choose optimal actions based on real-time inputs

    Routing between workflows, escalation decisions

    Action

    Deliver user-facing responses within guardrails

    Conversational turns, report delivery

    Reflection

    Re-assess plan or safety posture

    Post-incident review, plan recalibration

    Recall

    Pull memory into active context

    Longitudinal review, personalization pulls

    {
      "engage_client_on_in_scope_topic": {
        "type": "action",
        "objective": "Engage the client on their current query or queries in order of severity, always personalizing responses to your understanding of the user, while handling any natural topic changes within the conversation",
        "actions": [
          "Address all of the user's queries. Provide upfront value quickly in your response before asking follow up questions...",
          "Ask specific, detailed follow up questions to personalize my response.",
          "Handle any topic changes within the natural flow of conversation...",
          "..."
        ],
        "intra_state_navigation_guidelines": [
          "When client introduces a new topic, handle it within this state rather than triggering a state change",
          "Track the current topic being discussed in the conversation context",
          "If client changes topic, explicitly acknowledge the change and continue engagement on new topic",
          "..."
        ],
        "action_guidelines": [
          "Personalize all responses to the client's user model and your understanding of the user...",
          "Provide upfront value quickly in your response before asking follow up questions...",
          "..."
        ],
        "boundary_constraints": [
          "Never trigger state changes for topic switches",
          "Never force the client back to a previous topic unless they request it",
          "..."
        ],
        "exit_conditions": [
          {
            "description": "The client has finished discussing the current topic and there are potentially other topics to review...",
            "next_state": "reflect_on_conversation_topics"
          },
          {
            "description": "The client strongly and explicitly requests to immediately terminate the session",
            "next_state": "end_session"
          }
        ]
      }
    }
    START(new user) -> [A] welcome_patient
    START(returning user) -> [A] welcome_patient
    
    [A] welcome_patient
      (Client ready to proceed with check-in) -> [A] medication_adherence_check
    
    [A] medication_adherence_check
      (Medication information provided) -> [A] vasodilator_check
      (Medication concerns identified) -> [A] assess_medication_impact
      ...
    
    [A] check_chest_pain
      (No concerning findings) -> [A] check_shortness_of_breath
      (Concerning features present) -> [R] reflect_on_session_data
      ...
    
    [R] reflect_on_session_data -> [D] determine_exercise_clearance
    
    [D] determine_exercise_clearance
      (All criteria met) -> [A] summarize_recommendations_approved
      (Disqualifying findings) -> [A] summarize_recommendations_disqualified
      ...
    
    [A] patient_questions
      (No further questions) -> [A] end_session
    
    [A] end_session -> END