Skip to content

feat: pre invocation prompt hook#3852

Open
cape2333 wants to merge 15 commits intocamel-ai:masterfrom
cape2333:feat-pre-invocation-prompt-hook
Open

feat: pre invocation prompt hook#3852
cape2333 wants to merge 15 commits intocamel-ai:masterfrom
cape2333:feat-pre-invocation-prompt-hook

Conversation

@cape2333
Copy link
Copy Markdown
Contributor

Related Issue Fixes #3487

Summary

  • Add a MessageMiddleware base class and middleware pipeline to ChatAgent, enabling pre-invocation
    (request) and post-invocation (response) hooks for intercepting and transforming messages sent to /
    received from the model backend
  • Introduce MiddlewareContext (carries model type, agent ID, iteration info) and MiddlewareError for
    structured error propagation
  • Integrate middleware execution into both sync (_get_model_response) and async (_aget_model_response)
    code paths
  • Add an end-to-end example demonstrating user-profile injection and sensitive-data scrubbing middleware
  • Add unit tests covering request/response modification, middleware ordering, async path, and error
    wrapping

Description

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Checklist

  • I have read and agree to the AI-Generated Code Policy (required)
  • I have linked this PR to an issue (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and run uv lock
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed
  • I have added examples if this is a new feature

If you are unsure about any of these, don't hesitate to ask. We are here to help!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 18, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 543c4a53-b1c3-4c37-9728-84bcf1d1e820

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable poems in the walkthrough.

Disable the reviews.poem setting to disable the poems in the walkthrough.

Copy link
Copy Markdown
Collaborator

@waleedalzarooni waleedalzarooni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @cape2333,

A couple of quick comments from me!

@fengju0213 fengju0213 added this to the Sprint 49 milestone Mar 2, 2026
@fengju0213 fengju0213 requested review from Zephyroam and a7m-1st March 4, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Pre-Invocation Prompt Hook

5 participants