Support research mode flag in dynamic pathways#442
Conversation
This lets us publish pathways that invoke research mode. This is done using the `researchMode` flag
There was a problem hiding this comment.
Pull request overview
This pull request adds support for a new optional researchMode boolean flag that can be specified in dynamic pathway definitions. The flag flows through the pathway creation, storage, and execution layers to enable research mode functionality in downstream pathway execution (specifically run_workspace_agent which invokes sys_entity_agent).
Key changes:
- Added
researchModeas an optional boolean field in the GraphQLPromptInputschema - Implemented extraction and preservation of
researchModein PathwayManager's prompt object creation logic - Modified executeWorkspace to extract
researchModefrom the original prompt and pass it to cortex pathways, with a default value offalsewhen not provided
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/pathwayManager.js | Adds researchMode to GraphQL PromptInput schema and implements extraction/preservation logic in _createPromptObject method |
| server/executeWorkspace.js | Extracts researchMode from originalPrompt and includes it in cortexArgs for run_workspace_agent pathway, with a default of false |
Comments suppressed due to low confidence (1)
server/executeWorkspace.js:145
- The
researchModeextraction and defaulting logic forrun_workspace_agentis not covered by tests. Given that this repository has comprehensive test coverage for cortex pathway argument transformation (see tests/unit/graphql_executeWorkspace_transformation.test.js), tests should be added to verify:
researchModeis correctly extracted fromoriginalPromptand added tocortexArgsresearchModedefaults tofalsewhen not provided inoriginalPromptresearchModefrompathwayArgsis respected when already present
This is particularly important since line 104's comment mentions checking "if not already in pathwayArgs", but the current implementation doesn't actually check this condition.
// Extract researchMode from originalPrompt if not already in pathwayArgs
// originalPrompt could be the original object from JSON or a transformed Prompt object
if (originalPrompt && typeof originalPrompt === 'object' && originalPrompt.researchMode !== undefined) {
cortexArgs.researchMode = originalPrompt.researchMode;
}
// Transform context parameters to agentContext array format (only if agentContext not already provided)
if (!cortexArgs.agentContext && (cortexArgs.contextId || cortexArgs.contextKey || cortexArgs.altContextId || cortexArgs.altContextKey)) {
const agentContext = [];
// Add primary context if present
if (cortexArgs.contextId) {
agentContext.push({
contextId: cortexArgs.contextId,
contextKey: cortexArgs.contextKey || null,
default: true
});
}
// Add alternate context if present
if (cortexArgs.altContextId) {
agentContext.push({
contextId: cortexArgs.altContextId,
contextKey: cortexArgs.altContextKey || null,
default: false
});
}
// If we have at least one context, set agentContext and remove old params
if (agentContext.length > 0) {
cortexArgs.agentContext = agentContext;
delete cortexArgs.contextId;
delete cortexArgs.contextKey;
delete cortexArgs.altContextId;
delete cortexArgs.altContextKey;
}
}
// Ensure researchMode defaults to false if not provided
if (cortexArgs.researchMode === undefined) {
cortexArgs.researchMode = false;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Extract researchMode from originalPrompt if not already in pathwayArgs | ||
| // originalPrompt could be the original object from JSON or a transformed Prompt object | ||
| if (originalPrompt && typeof originalPrompt === 'object' && originalPrompt.researchMode !== undefined) { |
There was a problem hiding this comment.
The comment states "if not already in pathwayArgs", but the code unconditionally overwrites cortexArgs.researchMode without checking if it already exists. This is inconsistent with how agentContext is handled on line 111, where it explicitly checks !cortexArgs.agentContext before setting it.
Consider checking if researchMode already exists in cortexArgs before extracting it from originalPrompt to avoid unexpectedly overwriting a value that was already provided in the pathway arguments. The logic should respect an explicitly provided value in pathwayArgs over the one from originalPrompt.
| if (originalPrompt && typeof originalPrompt === 'object' && originalPrompt.researchMode !== undefined) { | |
| if ( | |
| cortexArgs.researchMode === undefined && | |
| originalPrompt && | |
| typeof originalPrompt === 'object' && | |
| originalPrompt.researchMode !== undefined | |
| ) { |
| prompt: String! | ||
| files: [String!] | ||
| cortexPathwayName: String | ||
| researchMode: Boolean |
There was a problem hiding this comment.
The researchMode property is being added to PromptInput, which is used for creating/updating pathways via the GraphQL mutation. However, there is no corresponding researchMode field in the Pathway output type (lines 481-484).
While this may be intentional if researchMode is only needed at creation time and not for querying, consider whether API consumers might need to retrieve this property when fetching pathway information. If pathways can be queried, the researchMode flag should likely be included in the output type for consistency.
This lets us publish pathways that invoke research mode. This is done using the
researchModeflag.This pull request introduces support for a new optional
researchModeproperty in the pathway execution flow, ensuring that it is preserved and passed through all relevant layers of the system. The changes ensure thatresearchModeis included in the prompt structure, GraphQL schema, and execution logic, allowing downstream components to leverage this flag as needed.Support for researchMode property:
PromptGraphQL type definition to include an optionalresearchModeBoolean property, allowing clients to specify this flag when constructing prompts.PathwayManagerto extractresearchModefrom prompt items, preserve it when building prompt objects, and include it in the prompt if present. [1] [2]Pathway execution enhancements:
executeWorkspace.jsto extractresearchModefrom the original prompt and include it in the arguments passed to the Cortex pathway, ensuring the flag is available during execution. [1] [2]