File size: 1,270 Bytes
3b0d6b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from abc import ABC, abstractmethod
from dataclasses import dataclass, field

from models import RunStatus


@dataclass
class RunContext:
    work_dir: str          # path inside container
    task_prompt: str       # full task description for the agent
    success_cmd: str       # command to verify success
    time_limit_s: int = 300
    token_limit: int = 200000
    repo_url: str = ""     # repo URL for host-side adapters (e.g. ClaudeCode)
    repo_ref: str = "main" # git branch/tag to clone


@dataclass
class RunResult:
    status: RunStatus
    duration_s: float = 0.0
    tokens_input: int = 0
    tokens_output: int = 0
    cost_usd: float = 0.0
    tests_total: int = 0
    tests_passed: int = 0
    diff_text: str = ""
    trajectory: list = field(default_factory=list)
    errors_count: int = 0
    tool_calls: int = 0
    raw_output: str = ""


class AgentAdapter(ABC):
    def __init__(self, config: dict = None):
        self.config = config or {}

    @abstractmethod
    def name(self) -> str: ...

    @abstractmethod
    async def run(self, ctx: RunContext, sandbox) -> RunResult:
        """Run the agent in the given sandbox. sandbox is a core.sandbox.Sandbox instance."""
        ...

    @abstractmethod
    def is_available(self) -> bool: ...