Tool framework extension#22995
Draft
luisorofino wants to merge 16 commits intoloa/openmetrics-ai-genfrom
Draft
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files🚀 New features to boost your workflow:
|
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.
What does this PR do?
Extends the AI tool framework with two new tool modules:
1.
ddev/src/ddev/ai/tools/fs/- Filesystem tools backed by aFileRegistry:ReadFileTool: reads file contents with line numbers and offset/limit paginationCreateFileTool: creates a new file and registers it; auto-creates parent directoriesEditFileTool: replaces an exact string within a registered file (fails if ambiguous or if the file was modified externally)AppendFileTool: appends content to the end of a registered file2.
ddev/src/ddev/ai/tools/http/- HTTP Tools:HttpGetTool: performs an HTTP GET request and returns the status code and body (truncated if large)The
FileRegistryis the key addition: it tracks a SHA-256 hash of each file's last-known content and issues a per-fileasyncio.Lock. Write tools (edit_file,append_file) verify the hash before writing — if the file was modified externally since the last read, the tool fails and asks the agent to re-read before retrying. This prevents lost writes when the agent's view of a file is stale. Also, it allows us to stop the agent from writing on a file that was not previously created by him, avoiding security problems.Motivation
The agent currently only has shell and grep tools — no way to safely create or modify files. Adding write tools naively creates a risk of the agent overwriting concurrent changes or working off a stale mental model of the file. The registry+hash pattern addresses this: the agent must read a file (or create it) before it can write it, and any external modification is detected before the write is committed. Also, only files created by the agent are allowed to be written to.
Review checklist (to be filled by reviewers)
qa/skip-qalabel if the PR doesn't need to be tested during QA.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged