Python API Reference
Complete API reference for the Autohand SDK Python. The SDK spawns the Autohand Code CLI as a subprocess and communicates over JSON-RPC.
Installation
pip install autohand-sdk
uv add autohand-sdk
AutohandSDK
Main async API for controlling the Autohand Code CLI.
Constructor
AutohandSDK(config: SDKConfig | None = None, **kwargs)
Common args: cwd, cli_path, debug, timeout, model, provider, api_key, permission_mode, skills, etc.
Lifecycle
await sdk.start()
await sdk.stop()
await sdk.close()
Also supports async context manager: async with AutohandSDK(...) as sdk:
Prompting
async for event in sdk.stream_prompt(message: str, **kwargs):
...
await sdk.prompt(message: str, **kwargs)
Control Methods
await sdk.abort(reason="User cancelled")
await sdk.respond_to_permission(request_id, decision="allow", allowed=True, remember=False)
await sdk.set_model("fantail2")
await sdk.set_agent("code-reviewer")
await sdk.set_temperature(0.2)
Information Methods
state = await sdk.get_state()
messages = await sdk.get_messages(limit=20)
models = await sdk.get_models()
agents = await sdk.get_agents()
account = await sdk.get_account_info()
await sdk.save_session()
CLI 0.9.13 run options
Configure the CLI process through SDKConfig before startup.
max_requests,max_duration_secondsset the request budget and wall-clock limit in seconds.allowed_tools,disallowed_toolsaccept lists of tool patterns.profile,setting_overridesselect a saved profile and apply ordered run-only overrides.no_daemon,sync_settings,search_enginecontrol background services, settings synchronization, and web search.
Use sdk.on_notification and the packet’s method and params attributes to read original CLI notifications. See run option semantics and notification payloads.
CLI Runtime Control
The current Python SDK exposes the v1.0.4 control surface on both Agent and AutohandSDK.
- Lifecycle:
reset,create_browser_handoff,attach_browser_handoff,attach_latest_browser_handoff. - Auto-mode:
start_automode,get_automode_status,pause_automode,resume_automode,cancel_automode,get_automode_log. - Approvals and sessions:
acknowledge_permission,respond_to_directory_access,acknowledge_directory_access,decide_changes,get_history,get_session,attach_session. - Integrations:
set_yolo,set_yolo_compat,set_vscode_mcp_tools,respond_to_mcp_invocation,get_learning_recommendations,update_learned_skills,generate_skill,get_tools_registry,set_context_compact.
Read Control the Autohand Code CLI from every SDK for behavior, safety contracts, aliases, and the cross-language name map.
Events
Events are dictionaries. Common types:
agent_start- Agent started a sessionmessage_update- Streaming assistant text deltatool_start- Tool execution startedtool_end- Tool execution completedpermission_request- Runtime pause for approvalautomode_iteration,automode_complete, andautomode_error- Auto-mode lifecycleerror- Transport, runtime, or execution failure
Common fields have both camelCase and snake_case aliases: sessionId/session_id, toolName/tool_name, etc.
See Hooks and events for the complete normalized event contract.
Types
SDKConfig
@dataclass
class SDKConfig:
cwd: str = "."
cli_path: str | None = None
debug: bool = False
timeout: int = 300000
model: str | None = None
provider: str | None = None
api_key: str | None = None
permission_mode: str | None = None
skills: list[str] | None = None
Exceptions
from autohand_sdk import RPCError, RequestTimeoutError, TransportNotStartedError
TransportNotStartedError- request attempted before start()RequestTimeoutError- no JSON-RPC response before timeoutRPCError- CLI returned a JSON-RPC error response (hascodeanddata)