Source code for oas2mcp.agent.state

"""Typed state definitions for ``oas2mcp`` agents.

Purpose:
    Define the state carried through stateful OpenAPI enhancement workflows.

Design:
    - Use ``TypedDict`` because LangChain v1 custom agent state requires it.
    - Keep the state centered on the source URL and progressively enriched API
      understanding.
    - Store deterministic catalog artifacts plus enhancer results so they can
      later be exported into an enhanced spec/config surface.

Examples:
    .. code-block:: python

        state: OpenApiEnhancementState = {
            "source_url": "https://example.com/openapi.json",
        }
"""

from __future__ import annotations

from typing import NotRequired

from langchain.agents import AgentState


[docs] class OperationEnhancementRecord(AgentState): """Serializable enhancer result stored in agent state."""
[docs] operation_key: str
[docs] operation_slug: str
[docs] final_kind: str
[docs] title: str
[docs] description: str
[docs] requires_confirmation: bool
[docs] tool_name: str | None
[docs] resource_uri: str | None
[docs] notes: list[str]
[docs] class OpenApiEnhancementState(AgentState): """State carried through the OpenAPI enhancement workflow."""
[docs] source_url: str
[docs] catalog: NotRequired[object]
[docs] candidate_bundle: NotRequired[object]
[docs] catalog_summary_context: NotRequired[object]
[docs] catalog_summary: NotRequired[object]
[docs] operation_keys: NotRequired[list[str]]
[docs] current_operation_key: NotRequired[str]
[docs] remaining_operation_keys: NotRequired[list[str]]
[docs] enhancement_todo: NotRequired[list[str]]
[docs] completed_steps: NotRequired[list[str]]
[docs] enhanced_operations: NotRequired[list[OperationEnhancementRecord]]
[docs] notes: NotRequired[list[str]]