Skip to content

Commit b09b200

Browse files
committed
Split teaagent/runner.py into a package with separated types module
- Extract ToolRequest, FinalAnswer, Decision, DecisionFn, ApprovalRequest, ApprovalHandler, and RunResult into _types.py - Rename runner.py → _core.py, importing types from the sibling module - Add __init__.py re-exporting all public symbols for backward-compatible imports
1 parent d12c132 commit b09b200

4 files changed

Lines changed: 81 additions & 51 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to TeaAgent are tracked here.
1111
- Split `teaagent/cli/_handlers.py` into a `teaagent/cli/_handlers/` package and extracted agent-run lifecycle logic into `_agent.py` while preserving command handler imports.
1212
- Continued splitting `teaagent/cli/_handlers/` by moving doctor, memory, model, MCP, misc, and audit handlers into dedicated modules and keeping stable re-exports in `__init__.py`.
1313
- Split `teaagent/llm_conformance.py` into a `teaagent/llm_conformance/` package with `_types.py` and `_runner.py`, preserving existing imports.
14+
- Split `teaagent/runner.py` into a `teaagent/runner/` package with `_types.py` and `_core.py`, preserving existing `teaagent.runner` imports.
1415
- Made `teaagent.cli.main()` accept injectable `_adapter_factory`, `_serve_mcp_http`, `_check_graphqlite`, `_check_llm`, and `_run_model_conformance` keyword arguments, enabling handler extraction without breaking existing tests.
1516
- Split `teaagent/workspace_tools.py` into a `teaagent/workspace_tools/` package with four focused modules: `_config.py`, `_helpers.py`, `_shell.py`, `_files.py`. Backward-compatible public imports preserved via `__init__.py` re-exports.
1617
- Expanded audit string redaction with patterns for JWT tokens, AWS access keys (`AKIA...`), and GitHub personal access tokens (`ghp_...`, `github_pat_...`).

teaagent/runner/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from ._core import AgentRunner
2+
from ._types import (
3+
ApprovalHandler,
4+
ApprovalRequest,
5+
Decision,
6+
DecisionFn,
7+
FinalAnswer,
8+
RunResult,
9+
ToolRequest,
10+
)
11+
12+
__all__ = [
13+
'AgentRunner',
14+
'ApprovalHandler',
15+
'ApprovalRequest',
16+
'Decision',
17+
'DecisionFn',
18+
'FinalAnswer',
19+
'RunResult',
20+
'ToolRequest',
21+
]
Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable
4-
from dataclasses import dataclass, field
5-
from typing import Any, Optional, Union
3+
from typing import Any, Optional
64
from uuid import uuid4
75

8-
from teaagent.audit import AuditLogger, redact_tool_arguments
6+
from teaagent.audit import AuditLogger
97
from teaagent.budget import RunBudget
108
from teaagent.context import ContextCompactor
119
from teaagent.errors import (
@@ -17,53 +15,7 @@
1715
from teaagent.policy import ApprovalPolicy, PermissionMode
1816
from teaagent.tools import ToolRegistry
1917

20-
21-
@dataclass(frozen=True)
22-
class ToolRequest:
23-
tool_name: str
24-
arguments: dict[str, Any]
25-
call_id: str = field(default_factory=lambda: uuid4().hex)
26-
27-
28-
@dataclass(frozen=True)
29-
class FinalAnswer:
30-
content: str
31-
metadata: dict[str, Any] = field(default_factory=dict)
32-
33-
34-
Decision = Union[ToolRequest, FinalAnswer]
35-
DecisionFn = Callable[[dict[str, Any]], Decision]
36-
37-
38-
@dataclass(frozen=True)
39-
class ApprovalRequest:
40-
call_id: str
41-
tool_name: str
42-
arguments: dict[str, Any]
43-
reason: str
44-
annotations: dict[str, bool]
45-
46-
def to_dict(self) -> dict[str, Any]:
47-
return {
48-
'call_id': self.call_id,
49-
'tool_name': self.tool_name,
50-
'arguments': redact_tool_arguments(self.arguments),
51-
'reason': self.reason,
52-
'annotations': self.annotations,
53-
}
54-
55-
56-
ApprovalHandler = Callable[[ApprovalRequest], bool]
57-
58-
59-
@dataclass(frozen=True)
60-
class RunResult:
61-
run_id: str
62-
final_answer: Optional[FinalAnswer]
63-
iterations: int
64-
tool_calls: int
65-
status: str
66-
metadata: dict[str, Any] = field(default_factory=dict)
18+
from ._types import ApprovalHandler, ApprovalRequest, DecisionFn, FinalAnswer, RunResult
6719

6820

6921
class AgentRunner:

teaagent/runner/_types.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Callable
4+
from dataclasses import dataclass, field
5+
from typing import Any, Optional, Union
6+
from uuid import uuid4
7+
8+
from teaagent.audit import redact_tool_arguments
9+
10+
11+
@dataclass(frozen=True)
12+
class ToolRequest:
13+
tool_name: str
14+
arguments: dict[str, Any]
15+
call_id: str = field(default_factory=lambda: uuid4().hex)
16+
17+
18+
@dataclass(frozen=True)
19+
class FinalAnswer:
20+
content: str
21+
metadata: dict[str, Any] = field(default_factory=dict)
22+
23+
24+
Decision = Union[ToolRequest, FinalAnswer]
25+
DecisionFn = Callable[[dict[str, Any]], Decision]
26+
27+
28+
@dataclass(frozen=True)
29+
class ApprovalRequest:
30+
call_id: str
31+
tool_name: str
32+
arguments: dict[str, Any]
33+
reason: str
34+
annotations: dict[str, bool]
35+
36+
def to_dict(self) -> dict[str, Any]:
37+
return {
38+
'call_id': self.call_id,
39+
'tool_name': self.tool_name,
40+
'arguments': redact_tool_arguments(self.arguments),
41+
'reason': self.reason,
42+
'annotations': self.annotations,
43+
}
44+
45+
46+
ApprovalHandler = Callable[[ApprovalRequest], bool]
47+
48+
49+
@dataclass(frozen=True)
50+
class RunResult:
51+
run_id: str
52+
final_answer: Optional[FinalAnswer]
53+
iterations: int
54+
tool_calls: int
55+
status: str
56+
metadata: dict[str, Any] = field(default_factory=dict)

0 commit comments

Comments
 (0)