feat: add structured final output#1
Merged
Merged
Conversation
7e6bfea to
3a7584f
Compare
3a7584f to
88adab6
Compare
Member
Author
|
Final implementation report:
Validation:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Localagent can now ask Pi to finish with schema-validated JSON while still letting the agent use normal tools first.
This matters for local-model workflows like PR classification, where the model needs to inspect evidence before returning machine-readable metadata.
The implementation creates a temporary Pi extension with a schema-backed final_json tool, runs Pi with that extension, and prints only the captured JSON after the tool is called.
What Changed
The feature lives in localagent, not Pi.
Localagent generates the final-output extension per run and wires it into the existing Pi launch path.
--final-schema <path>and--schema <path>.LOCALAGENT_FINAL_SCHEMA.final_jsonPi tool from the supplied object schema.--tools bashbecomesbash,final_json.Testing
I tested both the local code paths and the real PR-classification use case with Gemma served through LM Studio.
npm run checknode dist/src/cli/main.js --statusnode dist/src/cli/main.js --session-dir /tmp/localagent-smoke-sessions --final-schema /tmp/localagent-local-model-classifier.schema.json --tools bash -p "Read the PR contents before answering. Use gh to inspect https://github.com/openclaw/openclaw/pull/80568, including title, body, changed files, and enough diff/context to classify it. Classify whether this PR is about local models or not. Return the final answer only by calling final_json."node dist/src/cli/main.js --session-dir /tmp/localagent-smoke-sessions-assert --final-schema /tmp/localagent-local-model-classifier.schema.json --tools bash -p "..." | tee /tmp/localagent-pr-80568-classification.json | jq -e '.is_local_model_related == true and (.relevance == "relevant" or .relevance == "highly_relevant") and (.evidence | length > 0)'The smoke test classified PR 80568 as local-model related with
relevance: "highly_relevant".Risks
The feature depends on the model actually calling the
final_jsontool.If it does not, localagent fails clearly instead of returning unstructured output.
--final-schemacannot be combined with--no-tools.--mode rpcis rejected because localagent owns stdout handling for this mode.