Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9c2b227
feat(sdk): add ask oracle tool
enyst Jun 11, 2026
3daa1ce
Revise Oracle description for clarity and intent
enyst Jun 11, 2026
ed274a8
refactor(sdk): simplify oracle consultation
openhands-agent Jun 12, 2026
ce9712f
Merge main into ask oracle tool
enyst Jun 13, 2026
41f70f7
Fix ask oracle profile precedence
openhands-agent Jun 13, 2026
994c508
Clarify SDK built-in tool grouping
enyst Jun 15, 2026
27da708
Merge main into ask oracle tool
enyst Jun 21, 2026
759cf96
Fix pyright warnings after main merge
enyst Jun 21, 2026
8737df2
Fix ask oracle example numbering
enyst Jun 21, 2026
2faff61
Merge branch 'main' into feat/ask-oracle-tool
enyst Jun 22, 2026
4a5d3cd
Merge branch 'main' into feat/ask-oracle-tool
enyst Jun 24, 2026
32f8ce3
refactor(tools): move ask_oracle to openhands-tools, resolve 'oracle'…
enyst Jun 24, 2026
0b6c173
test(ask_oracle): make example + .pr evidence end-to-end
enyst Jun 25, 2026
1c7012d
Merge remote-tracking branch 'upstream/main' into feat/ask-oracle-tool
enyst Aug 3, 2026
b977f4d
chore(ask_oracle): adapt to main after merge
enyst Aug 3, 2026
f9d6c59
fix(ask_oracle): renumber example to 58 to avoid collision with main
openhands-agent Aug 17, 2026
081096c
chore: merge main into feat/ask-oracle-tool
openhands-agent Aug 17, 2026
0aa2097
Merge branch 'main' into feat/ask-oracle-tool
enyst Aug 17, 2026
a66c2a5
fix(ask_oracle): route Oracle calls through conversation LLM registry
openhands-agent Aug 18, 2026
acd9d9a
chore: Remove PR-only artifacts [automated]
Aug 18, 2026
83a5862
fix(tools): use canonical Oracle observation text
enyst Aug 18, 2026
5dfdf7b
fix(ci): allowlist Oracle tool metadata schema
enyst Aug 18, 2026
c4fec19
fix(examples): isolate Oracle profile storage
enyst Aug 24, 2026
194c8ce
chore: remove unrelated security test changes
enyst Aug 24, 2026
6753afc
Merge branch 'main' into feat/ask-oracle-tool
enyst Aug 25, 2026
78092eb
test: refresh ask oracle PR evidence
enyst Aug 26, 2026
fbde5e3
Merge branch 'main' into feat/ask-oracle-tool
enyst Aug 26, 2026
5a094a6
chore: remove temporary PR evidence
enyst Aug 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/agent-server-openapi-weak-schema-allowlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
"reason": "Agent settings retain a backward-compatible extension surface while known security-sensitive fields remain typed.",
"owner": "OpenHands OSS"
},
{
"pointer": "/components/schemas/AskOracleTool/properties/meta/anyOf/0/additionalProperties",
"kind": "unrestricted-additional-properties",
"reason": "Tool metadata is intentionally extensible across tool providers.",
"owner": "OpenHands"
},
{
"pointer": "/components/schemas/BrowserClickTool/properties/meta/anyOf/0/additionalProperties",
"kind": "unrestricted-additional-properties",
Expand Down
78 changes: 78 additions & 0 deletions examples/01_standalone_sdk/58_ask_oracle_tool/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Consult the Oracle end-to-end with the ask_oracle tool.

The Oracle is a saved LLM profile resolved by convention under the name
``oracle``. This example wires two profiles — the agent's primary model and a
separate ``oracle`` model — adds ``Tool(name="ask_oracle")`` to the agent, then
drives a normal conversation: the agent decides to call ``ask_oracle``, the tool
consults the ``oracle`` profile, and the agent uses the Oracle's answer to reply.

Usage:
LLM_API_KEY=... LLM_BASE_URL=https://llm-proxy.app.all-hands.dev \
uv run python examples/01_standalone_sdk/58_ask_oracle_tool/main.py

Note:
The example saves the ``oracle`` profile in a temporary directory so it
does not modify the user's default profile store.
"""

import os
import tempfile

from pydantic import SecretStr

from openhands.sdk import LLM, Agent, LocalConversation, Tool
from openhands.sdk.llm.llm_profile_store import LLMProfileStore
from openhands.tools.ask_oracle import ORACLE_PROFILE_NAME


DEFAULT_BASE_URL = "https://llm-proxy.app.all-hands.dev"
# The agent's primary model (follows the standard LLM_MODEL env like other
# examples). The Oracle defaults to the same model; override ASK_ORACLE_MODEL to
# point the "oracle" profile at a different/stronger model.
PRIMARY_MODEL = os.getenv("ASK_ORACLE_PRIMARY_MODEL") or os.getenv(
"LLM_MODEL", "openai/gpt-5.5"
)
ORACLE_MODEL = os.getenv("ASK_ORACLE_MODEL", PRIMARY_MODEL)

api_key = os.getenv("LLM_API_KEY")
assert api_key is not None, "LLM_API_KEY environment variable is not set."
base_url = os.getenv("LLM_BASE_URL", DEFAULT_BASE_URL)

with tempfile.TemporaryDirectory() as profile_store_dir:
store = LLMProfileStore(profile_store_dir)
# The Oracle model is saved under the conventional profile name "oracle".
store.save(
ORACLE_PROFILE_NAME,
LLM(
model=ORACLE_MODEL,
api_key=SecretStr(api_key),
base_url=base_url,
usage_id="oracle",
),
include_secrets=True,
)

primary_llm = LLM(
model=PRIMARY_MODEL,
api_key=SecretStr(api_key),
base_url=base_url,
usage_id="primary",
)
agent = Agent(llm=primary_llm, tools=[Tool(name="ask_oracle")])
conversation = LocalConversation(
agent=agent,
workspace=os.getcwd(),
profile_store_dir=profile_store_dir,
)

print(f"Primary model: {conversation.agent.llm.model}")
print(f"Oracle model: {ORACLE_MODEL}")
conversation.send_message(
"Call the oracle to ask it for its opinion on the weather today, "
"then just tell me in two words how it's like."
)
conversation.run()

combined = conversation.state.stats.get_combined_metrics()
print(f"Total cost: ${combined.accumulated_cost:.6f}")
print(f"EXAMPLE_COST: {combined.accumulated_cost}")
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def __init__(
prompt_cache_key: str | None = None,
file_store: FileStore | None = None,
mcp_tool_provider: MCPToolProvider | None = None,
profile_store_dir: str | Path | None = None,
**_: object,
):
"""Initialize the conversation.
Expand Down Expand Up @@ -295,6 +296,8 @@ def __init__(
file_store: Optional FileStore to use for conversation state and EventLog
persistence. If provided, this takes precedence over persistence_dir
for state and EventLog storage.
profile_store_dir: Optional directory containing saved LLM profiles.
Defaults to ``~/.openhands/profiles``.
"""
super().__init__() # Initialize with span tracking
# Mark cleanup as initiated as early as possible to avoid races or partially
Expand Down Expand Up @@ -482,7 +485,7 @@ def _default_callback(e):
# Agent initialization is deferred to _ensure_agent_ready() for lazy loading
# This ensures plugins are loaded before agent initialization
self.llm_registry = LLMRegistry()
self._profile_store = LLMProfileStore()
self._profile_store = LLMProfileStore(profile_store_dir)
self._cipher = cipher

# Seed agent_context.secrets into the registry for every agent (regular
Expand Down
7 changes: 4 additions & 3 deletions openhands-sdk/openhands/sdk/tool/builtins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Implementing essential tools that doesn't interact with the environment.
"""SDK-resident tools that do not interact with the environment.

These are built in and are *required* for the agent to work.
`BUILT_IN_TOOLS` contains tools attached to every agent. `BUILT_IN_TOOL_CLASSES`
also includes optional SDK tools that are resolved by name from agent setup.

For tools that require interacting with the environment, add them to `openhands-tools`.
Tools that require interacting with the environment belong in `openhands-tools`.
"""

from openhands.sdk.tool.builtins.finish import (
Expand Down
2 changes: 2 additions & 0 deletions openhands-tools/openhands/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from importlib.metadata import PackageNotFoundError, version

from openhands.tools.ask_oracle import AskOracleTool
from openhands.tools.delegate import DelegationVisualizer
from openhands.tools.file_editor import FileEditorTool
from openhands.tools.preset.default import (
Expand All @@ -40,6 +41,7 @@

__all__ = [
"__version__",
"AskOracleTool",
"DelegationVisualizer",
"FileEditorTool",
"TaskToolSet",
Expand Down
36 changes: 36 additions & 0 deletions openhands-tools/openhands/tools/ask_oracle/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Ask-Oracle tool package.

Provides a read-only ``ask_oracle`` tool: a one-shot, tool-less sub-agent that
consults a stronger/more-capable LLM for a second opinion. The Oracle model is a
saved LLM profile, resolved by convention under the name ``oracle`` (see
``ORACLE_PROFILE_NAME``).

Usage:
from openhands.tools.ask_oracle import AskOracleTool

agent = Agent(
llm=llm,
tools=[Tool(name=AskOracleTool.name)],
)

The agent's active conversation LLM is never switched. The Oracle call sends only
the Oracle system prompt plus the agent's question and optional context, without
forwarding conversation history or tools.
"""

from openhands.tools.ask_oracle.definition import (
ORACLE_PROFILE_NAME,
AskOracleAction,
AskOracleObservation,
AskOracleTool,
)
from openhands.tools.ask_oracle.impl import AskOracleExecutor


__all__ = [
"ORACLE_PROFILE_NAME",
"AskOracleAction",
"AskOracleObservation",
"AskOracleExecutor",
"AskOracleTool",
]
114 changes: 114 additions & 0 deletions openhands-tools/openhands/tools/ask_oracle/definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""Action, observation, and tool definitions for the ask_oracle tool."""

from collections.abc import Sequence
from typing import TYPE_CHECKING, Final, Self

from pydantic import Field
from rich.text import Text

from openhands.sdk.tool.registry import register_tool
from openhands.sdk.tool.tool import (
Action,
Observation,
ToolAnnotations,
ToolDefinition,
)


if TYPE_CHECKING:
from openhands.sdk.conversation.state import ConversationState


# The Oracle model is a saved LLM profile resolved by convention under this
# name. Save a profile named "oracle" (e.g. via LLMProfileStore.save("oracle",
# llm)) and the tool will consult it. No agent setting or wiring is required.
ORACLE_PROFILE_NAME: Final[str] = "oracle"
Comment thread
all-hands-bot marked this conversation as resolved.


class AskOracleAction(Action):
"""Action for asking the Oracle for advice."""

question: str = Field(
description=(
"The specific question or dilemma to ask the Oracle about. Use this "
"when you are stuck, uncertain, or need a second opinion."
)
)
context: str | None = Field(
default=None,
description=(
"Optional extra context, such as approaches already tried, constraints, "
"or the recommendation you are considering."
),
)

@property
def visualize(self) -> Text:
content = Text()
content.append("Ask Oracle: ", style="bold cyan")
content.append(self.question)
if self.context:
content.append("\nContext: ", style="bold")
content.append(self.context)
return content


class AskOracleObservation(Observation):
"""Observation returned by the Oracle consultation."""

@property
def visualize(self) -> Text:
content = Text()
if self.is_error:
content.append("Oracle consultation failed", style="bold red")
else:
content.append("Oracle recommendation", style="bold green")
if self.text:
content.append("\n")
content.append(self.text)
return content


_DESCRIPTION = (
"Ask the Oracle for a second opinion. The Oracle is a smart model intended "
"to help with difficult reasoning.\n\n"
"Use this when you are stuck, uncertain, comparing approaches, or need a "
"higher-quality recommendation before proceeding.\n\n"
"Treat the Oracle's response as strong guidance and follow its recommendation "
"unless you have a clear reason not to."
)


class AskOracleTool(ToolDefinition[AskOracleAction, AskOracleObservation]):
"""Tool for consulting the Oracle (a saved LLM profile named "oracle")."""

@classmethod
def create(
cls,
conv_state: "ConversationState | None" = None, # noqa: ARG003
**params,
) -> Sequence[Self]:
if params:
raise ValueError("AskOracleTool does not accept parameters")

# Import here to keep module import light and avoid any import cycles.
from openhands.tools.ask_oracle.impl import AskOracleExecutor

return [
cls(
description=_DESCRIPTION,
action_type=AskOracleAction,
observation_type=AskOracleObservation,
executor=AskOracleExecutor(),
annotations=ToolAnnotations(
readOnlyHint=True,
destructiveHint=False,
idempotentHint=False,
openWorldHint=True,
),
)
]


# Automatically register when this module is imported.
register_tool(AskOracleTool.name, AskOracleTool)
Loading
Loading