This document describes the API specifications for the TeaAgent codebase, including public interfaces, data structures, and usage patterns.
class ChatAgentConfig:
"""Configuration for chat agent execution."""
@classmethod
def from_root(cls, root: str | Path) -> ChatAgentConfig:
"""Create configuration from workspace root directory."""
pass
def to_dict(self) -> dict[str, Any]:
"""Convert configuration to dictionary."""
passdef run_chat_agent(
config: ChatAgentConfig,
task: str,
*,
provider: str | None = None,
model: str | None = None,
effort: str | None = None,
budget: int | None = None,
permission_mode: str | None = None,
approval_handler: ApprovalHandler | None = None,
) -> RunResult:
"""Run the chat agent with given configuration and task."""
passclass ApprovalManager:
"""Manages approval workflow and permission enforcement."""
def __init__(
self,
approval_store: ApprovalStore,
permission_mode: PermissionMode,
jit_approval_enabled: bool = False,
):
"""Initialize approval manager."""
pass
def check_approval(
self,
request: ApprovalRequest,
) -> tuple[bool, str | None]:
"""Check if request is approved."""
pass
def add_approval(
self,
request: ApprovalRequest,
decision: bool,
) -> None:
"""Add approval decision."""
passclass ApprovalPolicy:
"""Policy for approval decisions."""
def __init__(
self,
approval_store: ApprovalStore,
permission_mode: PermissionMode,
):
"""Initialize approval policy."""
pass
def is_destructive_allowed(
self,
tool_name: str,
arguments: dict[str, Any],
) -> bool:
"""Check if destructive operation is allowed."""
passclass WorkspaceToolConfig:
"""Configuration for workspace tools."""
@classmethod
def from_root(cls, root: str | Path) -> WorkspaceToolConfig:
"""Create configuration from workspace root."""
pass
@property
def root(self) -> Path:
"""Get workspace root directory."""
passdef build_workspace_tool_registry(
root: str | Path,
) -> ToolRegistry:
"""Build tool registry for workspace operations."""
passdef read_file(
config: WorkspaceToolConfig,
args: dict[str, Any],
) -> dict[str, Any]:
"""Read file content."""
pass
def write_file(
config: WorkspaceToolConfig,
args: dict[str, Any],
) -> dict[str, Any]:
"""Write file content atomically."""
pass
def edit_at_hash(
config: WorkspaceToolConfig,
args: dict[str, Any],
) -> dict[str, Any]:
"""Edit file at specific line with hash validation."""
passdef run_shell(
config: WorkspaceToolConfig,
args: dict[str, Any],
) -> dict[str, Any]:
"""Run shell command safely."""
pass
def run_shell_argv(
config: WorkspaceToolConfig,
args: dict[str, Any],
) -> dict[str, Any]:
"""Run shell command with argv."""
passclass BackendRegistry:
"""Registry for backend systems."""
def register_knowledge_backend(
self,
name: str,
backend: KnowledgeSearchBackend,
) -> None:
"""Register knowledge backend."""
pass
def register_code_parse_backend(
self,
name: str,
backend: CodeParseBackend,
) -> None:
"""Register code parse backend."""
pass
def get_knowledge_backend(
self,
name: str,
) -> KnowledgeSearchBackend | None:
"""Get knowledge backend by name."""
pass
def get_code_parse_backend(
self,
name: str,
) -> CodeParseBackend | None:
"""Get code parse backend by name."""
passclass KnowledgeSearchBackend(Protocol):
"""Interface for knowledge search backends."""
def search(
self,
query: str,
root: Path,
) -> list[dict[str, Any]]:
"""Search knowledge base."""
pass
class CodeParseBackend(Protocol):
"""Interface for code parse backends."""
def parse(
self,
path: Path,
root: Path,
) -> dict[str, Any]:
"""Parse code structure."""
passclass ToolPermissionError(Exception):
"""Raised when tool operation is not permitted."""
pass
class ToolExecutionError(Exception):
"""Raised when tool execution fails."""
pass
class ConfigurationError(Exception):
"""Raised when configuration is invalid."""
pass
class BackendError(Exception):
"""Raised when backend operation fails."""
passclass ErrorContext:
"""Context for error reporting."""
def __init__(
self,
tool_name: str,
arguments: dict[str, Any],
error: Exception,
severity: str,
recovery_hint: str | None = None,
):
"""Initialize error context."""
pass
def to_dict(self) -> dict[str, Any]:
"""Convert to dictionary."""
passclass ConfigurationLoader:
"""Load configuration from various sources."""
def load_from_file(
self,
path: Path,
) -> dict[str, Any]:
"""Load configuration from file."""
pass
def load_from_env(
self,
prefix: str = 'TEAAGENT_',
) -> dict[str, Any]:
"""Load configuration from environment variables."""
pass
def load_from_args(
self,
args: argparse.Namespace,
) -> dict[str, Any]:
"""Load configuration from command-line arguments."""
passclass ConfigurationSchema:
"""Schema for configuration validation."""
def register_key(
self,
key: str,
type_: type,
default: Any,
required: bool = False,
validator: Callable[[Any], bool] | None = None,
) -> None:
"""Register configuration key."""
pass
def validate(
self,
config: dict[str, Any],
) -> bool:
"""Validate configuration against schema."""
pass@dataclass
class ApprovalRequest:
"""Request for approval."""
call_id: str
tool_name: str
arguments: dict[str, Any]
content_digest: str | None = None
destructive: bool = False@dataclass
class RunResult:
"""Result of agent execution."""
run_id: str
status: str
iterations: int
tool_calls: int
input_tokens: int
output_tokens: int
error: str | None = None@dataclass
class ToolResult:
"""Result of tool execution."""
ok: bool
result: Any
error: str | None = Nonefrom teaagent.chat_agent import ChatAgentConfig, run_chat_agent
config = ChatAgentConfig.from_root('/path/to/workspace')
result = run_chat_agent(
config,
task='Fix the bug in main.py',
provider='openai',
model='gpt-4',
permission_mode='prompt',
)from teaagent.workspace_tools._files import (
build_workspace_tool_registry,
WorkspaceToolConfig,
)
config = WorkspaceToolConfig.from_root('/path/to/workspace')
registry = build_workspace_tool_registry('/path/to/workspace')
result = registry.invoke(
'workspace_read_file',
{'path': 'main.py'},
)from teaagent.approval import ApprovalManager
from teaagent.policy import ApprovalStore, PermissionMode
store = ApprovalStore('/path/to/workspace')
manager = ApprovalManager(
store,
PermissionMode.PROMPT,
)
approved, reason = manager.check_approval(request)from teaagent.external_backends import (
register_knowledge_backend,
get_knowledge_backend,
)
# Register custom backend
register_knowledge_backend('my_backend', MyBackend())
# Use backend
backend = get_knowledge_backend('my_backend')
results = backend.search('query', Path('/path/to/workspace'))try:
result = registry.invoke('workspace_read_file', {'path': 'file.txt'})
except ToolPermissionError as e:
logger.error(f'Permission denied: {e}')
except ToolExecutionError as e:
logger.error(f'Execution failed: {e}')try:
config = ChatAgentConfig.from_root('/path/to/workspace')
except ConfigurationError as e:
logger.error(f'Invalid configuration: {e}')try:
results = backend.search('query', root)
except BackendError as e:
logger.error(f'Backend error: {e}')- Major version changes indicate breaking changes
- Minor version changes indicate new features
- Patch version changes indicate bug fixes
- Deprecated APIs will be marked with
@deprecateddecorator - Deprecated APIs will be removed in the next major version
- Migration guides will be provided for breaking changes
- Component-specific API documentation
- Type hints in source code
- Example usage in test files