33 lines
833 B
Python
33 lines
833 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]
|
|
token_usage: dict | None
|