-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add structured task outcomes to preset finish tool #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
malhotra5
wants to merge
15
commits into
main
Choose a base branch
from
add-task-outcome-structured-output
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
538fcc6
feat: add structured task outcomes to preset finish tool
openhands-agent a616bec
feat: persist structured task outcomes
openhands-agent a8d6804
fix: import task outcome models from sdk
openhands-agent 01f690b
fix: update SDK task outcome pin
openhands-agent e75572f
fix: renumber run metadata migration
openhands-agent e4ab709
Merge origin/main into task outcome PR
openhands-agent 25cf05b
fix: store raw finish tool response metadata
openhands-agent b39be5d
fix: update SDK pin for preset tool resolution
openhands-agent 1f42bb6
fix: use default agent finish tool params
openhands-agent f8ec40f
fix: use structured finish response option
openhands-agent 5f1cb9c
fix: pin simplified task outcome schema
openhands-agent b26029c
fix: pin deduped task outcome statuses
openhands-agent 15eeb5f
Merge main into add-task-outcome-structured-output
openhands-agent 7ec8a39
fix: address PR feedback and migration chain
openhands-agent d762e05
fix: satisfy backend pre-commit checks
openhands-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """Add run_metadata column to automation_runs. | ||
|
|
||
| Stores additional execution metadata captured after a run completes, such as | ||
| structured semantic task outcomes parsed from preset conversation finish actions. | ||
|
|
||
| Revision ID: 016 | ||
| Revises: 015 | ||
| Create Date: 2026-08-12 | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
|
|
||
| revision: str = "016" | ||
| down_revision: str = "015" | ||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column("automation_runs", sa.Column("run_metadata", sa.JSON, nullable=True)) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_column("automation_runs", "run_metadata") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| """Helpers for reading raw FinishTool responses from conversations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import logging | ||
| from typing import Any | ||
|
|
||
| import httpx | ||
|
|
||
| from openhands.automation.backends import get_backend | ||
| from openhands.automation.config import get_config | ||
| from openhands.automation.models import AutomationRun | ||
| from openhands.automation.utils.sandbox import get_sandbox_agent_url | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| ACTION_EVENT_KIND = "openhands.sdk.event.llm_convertible.action.ActionEvent" | ||
| FINISH_TOOL_NAME = "finish" | ||
|
|
||
|
|
||
| def finish_tool_response_from_event(event: dict[str, Any]) -> Any | None: | ||
| """Return the raw JSON-decoded arguments from a FinishTool action event.""" | ||
| if event.get("tool_name") != FINISH_TOOL_NAME: | ||
| return None | ||
|
|
||
| tool_call = event.get("tool_call") | ||
| if not isinstance(tool_call, dict): | ||
| return None | ||
|
|
||
| raw_arguments = tool_call.get("arguments") | ||
| if not isinstance(raw_arguments, str): | ||
| return None | ||
|
|
||
| try: | ||
| return json.loads(raw_arguments) | ||
| except json.JSONDecodeError: | ||
| logger.warning("Could not decode finish tool arguments as JSON") | ||
| return raw_arguments | ||
|
|
||
|
|
||
| def latest_finish_tool_response_from_events( | ||
| events: list[dict[str, Any]], | ||
| ) -> Any | None: | ||
| """Return the latest finish action response from newest-first events.""" | ||
| for event in events: | ||
| if event.get("tool_name") == FINISH_TOOL_NAME: | ||
| return finish_tool_response_from_event(event) | ||
| return None | ||
|
|
||
|
|
||
| async def fetch_latest_finish_tool_response( | ||
| client: httpx.AsyncClient, | ||
| agent_url: str, | ||
| session_key: str, | ||
| conversation_id: str, | ||
| ) -> Any | None: | ||
| """Fetch recent conversation actions and return the latest finish response.""" | ||
| response = await client.get( | ||
| f"{agent_url.rstrip('/')}/api/conversations/{conversation_id}/events/search", | ||
| params={ | ||
| "kind": ACTION_EVENT_KIND, | ||
| "sort_order": "TIMESTAMP_DESC", | ||
| "limit": 100, | ||
| }, | ||
| headers={"X-Session-API-Key": session_key}, | ||
| timeout=30.0, | ||
| ) | ||
| response.raise_for_status() | ||
| page = response.json() | ||
| items = page.get("items") if isinstance(page, dict) else None | ||
| if not isinstance(items, list): | ||
| return None | ||
| return latest_finish_tool_response_from_events(items) | ||
|
|
||
|
|
||
| async def fetch_latest_finish_tool_response_for_run( | ||
|
malhotra5 marked this conversation as resolved.
|
||
| run: AutomationRun, | ||
| conversation_id: str, | ||
| ) -> Any | None: | ||
| """Best-effort lookup of the latest raw FinishTool response for a run.""" | ||
| try: | ||
| backend = get_backend(run) | ||
| async with httpx.AsyncClient(timeout=60.0) as client: | ||
| if backend.is_local_mode: | ||
| ctx = await backend.get_execution_context(client) | ||
| return await fetch_latest_finish_tool_response( | ||
| client, | ||
| ctx.agent_url, | ||
| ctx.session_key, | ||
| conversation_id, | ||
| ) | ||
|
|
||
| if not run.sandbox_id: | ||
| return None | ||
|
|
||
| api_key = await backend.get_api_key() | ||
| result = await get_sandbox_agent_url( | ||
| client, | ||
| get_config().service.openhands_api_base_url, | ||
| api_key, | ||
| run.sandbox_id, | ||
| ) | ||
| if result is None: | ||
| return None | ||
| agent_url, session_key = result | ||
| return await fetch_latest_finish_tool_response( | ||
| client, | ||
| agent_url, | ||
| session_key, | ||
| conversation_id, | ||
| ) | ||
| except Exception as exc: | ||
| logger.warning( | ||
| "Could not fetch finish tool response for run %s conversation %s: %s", | ||
| run.id, | ||
| conversation_id, | ||
| exc, | ||
| ) | ||
| return None | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.