ForcePilot/backend/package/yuxi/agents/state.py
2026-06-01 22:28:45 +08:00

32 lines
804 B
Python

"""Define the state structures for the agent."""
from __future__ import annotations
from typing import Annotated, TypedDict
from langchain.agents import AgentState
def merge_artifacts(existing: list[str] | None, new: list[str] | None) -> list[str]:
"""Merge artifact file paths while preserving order and removing duplicates."""
if existing is None:
return new or []
if new is None:
return existing
return list(dict.fromkeys(existing + new))
class BaseState(AgentState):
"""Shared state fields for Yuxi agents."""
artifacts: Annotated[list[str], merge_artifacts]
class AgentStatePayload(TypedDict):
"""Serialized agent state payload consumed by the frontend."""
todos: list
files: dict
artifacts: list[str]
subagent_runs: list[dict]