From ce550a127b7dc972651bd15b9f09979a2c38688f Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Wed, 12 Aug 2026 00:02:23 +0900 Subject: feat: harden Python workflow and structured planning Replace the uv-specific skill with a portable Python skill and rewrite the default user system prompt as a concise, structured Markdown execution policy. Normalize a single fenced structured-JSON response, retry invalid skill selection with think disabled, validate selected skill output, and make coding plans keep editing and verification in one task. Document the file_edit patch payload, expose that contract in the tool catalog, and convert malformed patch input into a retryable tool failure instead of terminating the agent task. Update configuration and runtime tests for the Python skill, exact tool catalog, structured-output retry, and implementation-and-verification planning guidance. Verified with 82 Agent.Core tests and an agent-mcp Python scheduling scenario with 49 passing unittest cases. --- doc/Design.md | 1 + prompts/user-system.md | 59 ++++++++++++++++++++++- skills/python-via-uv/SKILL.md | 27 ----------- skills/python-via-uv/agents/openai.yaml | 4 -- skills/python/SKILL.md | 30 ++++++++++++ skills/python/agents/openai.yaml | 4 ++ src/Agent.Core/Runtime/AgentRuntime.cs | 61 ++++++++++++++--------- src/Agent.Core/Runtime/PlannerService.cs | 64 +++++++++++++++++-------- src/Agent.Core/Runtime/StructuredJson.cs | 22 +++++++++ src/Agent.Core/Tools/InternalToolCatalog.cs | 2 +- src/Agent.Windows/Tools/WindowsToolBackend.cs | 28 ++++++++--- tests/Agent.Core.Tests/ConfigurationTests.cs | 6 +-- tests/Agent.Core.Tests/PromptAndRuntimeTests.cs | 13 ++++- 13 files changed, 234 insertions(+), 87 deletions(-) delete mode 100644 skills/python-via-uv/SKILL.md delete mode 100644 skills/python-via-uv/agents/openai.yaml create mode 100644 skills/python/SKILL.md create mode 100644 skills/python/agents/openai.yaml create mode 100644 src/Agent.Core/Runtime/StructuredJson.cs diff --git a/doc/Design.md b/doc/Design.md index 3623cb4..68c7dbc 100644 --- a/doc/Design.md +++ b/doc/Design.md @@ -291,6 +291,7 @@ Ollamaに公開する現行Internal Tool catalogは次のとおりとする。 } ``` - overwrite/patch/atomic_replaceはwrite permissionを要求する。 +- `patch` operationの`patch` fieldは、JSON文字列化した`{"old_text":"...","new_text":"..."}`を受け取る。unified diffは受け付けない。`old_text`は対象file内で正確に1回だけ一致しなければならない。不正形式または一致数不正は再試行可能なTool failureとする。 - deleteはdelete permissionを要求する。 - renameはsource/destination双方にwrite permissionを要求する。destinationが既に存在する場合は拒否する(overwrite不可)。cross-volume renameは不支持でTool failureとして返す。 - rename transaction: PREPARE(source/destination検査+journal) → APPLY(File.Move) → VERIFY(source不存在/destination存在/hash一致) → COMMIT。crash recoveryはdestination hashがjournal記録と一致する場合のみdestinationからsourceへ戻す。 diff --git a/prompts/user-system.md b/prompts/user-system.md index f1d255b..9766b67 100644 --- a/prompts/user-system.md +++ b/prompts/user-system.md @@ -1,2 +1,57 @@ -あなたはユーザーの身近な相棒です。親しみやすく率直に会話し、考えを整理し、必要なときだけ実作業を提案・実行してください。 -分からないことは決めつけず確認し、利用可能なSkillとToolを選び、結果を確かめてから要点と次の一手を簡潔に伝えてください。 +# Role + +あなたは、依頼を安全かつ確実に完了する実行アシスタントです。 +親しみやすく率直に対話し、結果を先に簡潔に伝えてください。 + +# Priorities + +1. ユーザーの明示した目的、制約、値を守る。 +2. Sandbox Policyと利用可能なToolの範囲を守る。 +3. 実行結果を確認してから完了を報告する。 +4. 不明点を推測で埋めず、結果を変える判断だけ確認する。 + +# Understand the Request + +- 目的、成果物、作業directory、入力、出力、完了条件を整理する。 +- 指定されたpath、実行file、引数、文字列、数値を省略または変更しない。 +- 既存fileを変更する場合は、先に必要な範囲を読み取る。 +- 依頼されていない副作用や権限拡張を計画しない。 + +# Plan and Execute + +- 単純な依頼は小さなTaskとして、複雑な依頼は検証可能なTaskへ分ける。 +- 各Taskは一つの明確な成果に限定し、dependency順に実行する。 +- 利用可能なSkillが依頼に合う場合は、その手順を適用する。 +- 読取、編集、directory操作、process実行には対応するInternal Toolを使う。 +- Tool呼出しでは構造化引数を使い、shell形式の文字列へまとめない。 +- Tool失敗時は同じ呼出しを反復せず、errorと許可済みの代替を確認する。 +- Sandbox拒否を回避せず、必要なpath、権限、承認を具体的に示す。 + +# Working with Files + +- 作業は指定されたdirectory内に限定する。 +- 複雑な成果物は再利用可能なfileとして保存する。 +- 既存内容を維持する指定がある場合は、変更を必要最小限にする。 +- 一時file、backup、生成物を把握し、不要な残留を避ける。 + +# Running Programs + +- 承認済みの実行fileだけを直接起動する。 +- executable、cwd、argsを分け、引数の順序と値を維持する。 +- 作成するprogramやtestからdescendant processを生成しない。 +- 依頼なしにpackageをinstallしたりnetworkへ接続したりしない。 +- stdout、stderr、exit codeを確認し、期待結果と照合する。 + +# Verification + +- 成果物の存在だけでなく、主要動作、境界条件、失敗条件を確認する。 +- 可能なら決定的なtestを実行する。 +- 必要なTool結果が成功するまでTaskを完了扱いしない。 +- 未検証、skip、外部要因による失敗を成功として報告しない。 + +# Communication + +- 実行中は必要な進捗だけを短く伝える。 +- 最終応答には、結果、変更file、検証内容、残課題を含める。 +- 内部Tool名、Sandbox実装詳細、秘密情報、隠れた推論は利用者向け結果へ出さない。 +- 失敗時は原因と、ユーザーが次に取れる具体的な一手を示す。 diff --git a/skills/python-via-uv/SKILL.md b/skills/python-via-uv/SKILL.md deleted file mode 100644 index d840e4d..0000000 --- a/skills/python-via-uv/SKILL.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: python-via-uv -description: uv経由でPythonコードを作成・実行・検証する。ユーザーがPythonによる計算、データ処理、自動化、試作、デバッグ、またはスクリプト実行を求めたときに使用する。 ---- - -# Python via uv - -1. 作業directoryと必要な入出力を確認し、コードは許可されたdirectory内の`.py`へ`file_edit`で保存する。複雑なコードを`python -c`へ詰め込まない。 -2. 承認済み`uv.exe`を`process_run`し、projectではcwdから`uv python find --offline --no-python-downloads --resolve-links`、単独scriptでは同じ引数へ`--no-project`を追加してinterpreterの絶対pathを取得する。 -3. 取得した承認済み`python.exe`を別の`process_run`で起動し、`-I