Start a conversation in the local environment.
Payload to create a new conversation.
Contains an Agent configuration along with conversation-specific options.
Main agent implementation for OpenHands.
The Agent class provides the core functionality for running AI agents that can interact with tools, process messages, and execute actions. It inherits from AgentBase and implements the agent execution logic.
Example: >>> from openhands.sdk import LLM, Agent, Tool >>> llm = LLM(model="claude-sonnet-4-20250514", api_key=SecretStr("key")) >>> tools = [Tool(name="TerminalTool"), Tool(name="FileEditorTool")] >>> agent = Agent(llm=llm, tools=tools)
Working directory for agent operations and tool execution
Optional conversation ID. If not provided, a random UUID will be generated.
Controls when the conversation will prompt the user before continuing. Defaults to never.
Initial message to pass to the LLM
If set, the max number of iterations the agent will run before stopping. This is useful to prevent infinite loops.
x >= 1If true, the conversation will use stuck detection to prevent infinite loops.
Secrets available in the conversation
Mapping of tool names to their module qualnames from the client's registry. These modules will be dynamically imported on the server to register the tools for this conversation.
Successful Response
Information about a conversation running locally without a Runtime sandbox.
Unique conversation ID
The agent running in the conversation. This is persisted to allow resuming conversations and check agent configuration to handle e.g., tool changes, LLM changes, etc.
Workspace used by the agent to execute commands and read/write files. Not the process working directory.
Directory for persisting conversation state and events. If None, conversation will not be persisted.
Maximum number of iterations the agent can perform in a single run.
Whether to enable stuck detection for the agent.
Enum representing the current execution state of the conversation.
idle, running, paused, waiting_for_confirmation, finished, error, stuck, deleting Optional security analyzer to evaluate action risks.
List of activated knowledge skills name
Actions blocked by PreToolUse hooks, keyed by action ID
Messages blocked by UserPromptSubmit hooks, keyed by message ID
Conversation statistics for tracking LLM metrics
Registry for handling secrets and sensitive data
User-defined title for the conversation
A snapshot of metrics at a point in time.
Does not include lists of individual costs, latencies, or token usages.