Skip to content

cpex prompt hooks - #81

Open
madhu-mohan-jaishankar wants to merge 7 commits into
mainfrom
feat/cpex-prompt-hooks
Open

cpex prompt hooks#81
madhu-mohan-jaishankar wants to merge 7 commits into
mainfrom
feat/cpex-prompt-hooks

Conversation

@madhu-mohan-jaishankar

Copy link
Copy Markdown
Contributor

closes #5258 partially
pre and post hooks for Prompts

Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
@madhu-mohan-jaishankar madhu-mohan-jaishankar changed the title Feat/cpex prompt hooks cpex prompt hooks Aug 10, 2026

@lucarlig lucarlig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fix the prompt hook registration and CMF result mapping, then add the end-to-end coverage and documentation required by #5258. Prompt deny/error attribution should also say prompt rather than tool call.

Comment thread crates/contextforge-data-plane-cpex/src/runtime.rs
Comment thread crates/contextforge-data-plane-cpex/src/cmf.rs Outdated
Comment thread crates/contextforge-data-plane-lib/tests/gateway_plugins.rs
…ompt messages through CMF

Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
content: PromptRequest {
prompt_request_id: prompt_request_id.to_owned(),
name: prompt_name.to_owned(),
arguments: request.arguments.clone().unwrap_or_default().into_iter().collect(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:
change to
arguments: request.arguments.clone().map(HashMap::from_iter).unwrap_or_default(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed.

}
}

pub(crate) fn prompt_request_arguments(payload: &MessagePayload) -> Option<Map<String, Value>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question, why one is using Map and the other HashMap? do we need to make this conversion??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, rmcp has Map and cpex-core has HashMap.

payload: &MessagePayload,
) -> Option<GetPromptResult> {
let results = payload.message.get_prompt_results();
let result = results.first()?;

@dawid-nowak dawid-nowak Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This integration feels strange to be honest.. so perhaps we need better documentation here.

  1. Why do we check only first result here?
  2. And it looks like we are ignoring "result.is_error" flag?
  3. Are we always guaranteed, that CPEX will return ALL messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. fixed.
  2. fixed - is_error now fails the call with the plugin's error_message.
  3. cpex doesn't guarantee the return of all messages. so we check the count.


for (message, edited) in original.messages.iter_mut().zip(&result.messages) {
let projected = cmf_prompt_message(message, &result.prompt_request_id);
if serde_json::to_value(&projected).ok()? == serde_json::to_value(edited).ok()? {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this check, just to compare if CPEX has updated the message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes. created contextforge-org/cpex#163 to address this in cpex. if the round trip becomes lossless, this check goes away.

@dawid-nowak dawid-nowak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor nits and some questions :)

… prompt hooks

Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
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.

[CF-DATAPLANE] Add CPEX hooks for non-tool MCP pass-through calls

3 participants