Skip to content

Tool framework extension#22995

Draft
luisorofino wants to merge 16 commits intoloa/openmetrics-ai-genfrom
loa/tools-extension
Draft

Tool framework extension#22995
luisorofino wants to merge 16 commits intoloa/openmetrics-ai-genfrom
loa/tools-extension

Conversation

@luisorofino
Copy link

@luisorofino luisorofino commented Mar 20, 2026

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 a FileRegistry:

  • ReadFileTool: reads file contents with line numbers and offset/limit pagination
  • CreateFileTool: creates a new file and registers it; auto-creates parent directories
  • EditFileTool: 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 file

2. 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 FileRegistry is the key addition: it tracks a SHA-256 hash of each file's last-known content and issues a per-file asyncio.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)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

@luisorofino luisorofino added the qa/skip-qa Automatically skip this PR for the next QA label Mar 20, 2026
@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 99.63235% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (loa/openmetrics-ai-gen@8af3d01). Learn more about missing BASE report.

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ddev qa/skip-qa Automatically skip this PR for the next QA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant