Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello world")
3 changes: 3 additions & 0 deletions src/agent/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_core.messages import BaseMessage

Message = BaseMessage
66 changes: 17 additions & 49 deletions src/agent/state.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,27 @@
"""Graph state definition for the LangGraph agent."""

from __future__ import annotations

import operator
from dataclasses import dataclass, field
from pathlib import Path
from typing import Annotated, Any, TypedDict

from langchain_core.language_models import BaseChatModel
from langchain_core.messages import BaseMessage
from langgraph.channels import UntrackedValue
from langgraph.graph.message import add_messages

from ..config.settings import RepoConfig, Settings
from ..git_ops.repo import GitRepo


class AgentState(TypedDict, total=False):
"""Typed state dictionary for the LangGraph agent pipeline."""

# Immutable inputs (set once at graph entry) — not checkpointed
task: Annotated[str, UntrackedValue]
settings: Annotated[Settings, UntrackedValue]
repo_config: Annotated[RepoConfig, UntrackedValue]
branch: Annotated[str | None, UntrackedValue]

# Initialised in clone_and_branch, reused across nodes — not checkpointed
readme_preamble: Annotated[str, UntrackedValue]
messages: Annotated[list[BaseMessage], add_messages]
llm: Annotated[BaseChatModel, UntrackedValue]
git: Annotated[GitRepo, UntrackedValue]
repo_dir: Annotated[Path, UntrackedValue]
active_branch: Annotated[str, UntrackedValue]
from typing import Annotated, TypedDict

# Control flow
prompt_type: str
from .models import Message

# Plan phase
plan: dict[str, Any]
file_contents: str
plan_complete: bool

# Post-implement
changed_files: list[str]
@dataclass
class State:
"""Represents the state of the agent."""

# Test/fix loop
attempt: int
max_attempts: int
checks_passed: bool
test_output: str
fix_history: list[dict[str, str]]
task: str
repo_name: str
repo_path: Path
messages: list[Message] = field(default_factory=list)

# PR
pr_ready: bool

# Token tracking
token_usage: dict[str, int]
class AgentState(TypedDict):
"""Represents the state of the agent graph."""

# Final output
result: str
task: str
repo_name: str
repo_path: Path
messages: Annotated[list[Message], operator.add]
18 changes: 18 additions & 0 deletions tests/test_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from pathlib import Path

from src.agent.state import State


def test_state_initialization():
"""Tests the initialization of the State object."""
task = "Implement a new feature"
repo_name = "my-agent"
repo_path = Path("/tmp/my-agent")
state = State(task=task, repo_name=repo_name, repo_path=repo_path)

assert state.task == task
assert state.repo_name == repo_name
assert state.repo_path == repo_path
assert state.messages == []