Skip to main content

Assistant Research

The Assistant Research script module executes AI assistant research plans by making MCP API calls and vector searches. This is used internally by the platform's AI Assistant workflow to gather context before generating responses.

Functions

executeResearchPlan

Execute a complete research plan from the upstream prompt entity's JSON output.

const results = await executeResearchPlan();

Returns: An object containing:

FieldTypeDescription
researchResultsobjectMap of call ID to { success, data } or { success, error }
intentstringThe detected user intent from the research plan
navigationSuggestionobjectSuggested UI navigation action (if any)
reasoningstringThe planner's reasoning about the request

Side effects: Sets the following V8 globals for downstream entities:

  • researchResults — The full results map
  • intent — The detected intent string
  • navigationSuggestion — Navigation suggestion object
  • reasoning — The planner's reasoning

validateAssistantContext

Validate that the current workflow execution is running inside the assistant system org/env.

const { clientOrganizationId, clientEnvironmentId } = await validateAssistantContext();

Throws an error if the workflow's org/env does not match ASSISTANT_WORKFLOW_ORG_ID / ASSISTANT_WORKFLOW_ENV_ID.

mcpCall

Make an authenticated API call to the admin service.

const data = await mcpCall(method, path, params);
ParameterTypeDescription
methodstringHTTP method ("GET" or "POST")
pathstringAPI path (e.g., "/api/environments")
paramsobjectQuery params (GET) or request body (POST)

vectorSearch

Search the OpenAI vector store for documentation.

const results = await vectorSearch(query, limit?);
ParameterTypeDefaultDescription
querystringNatural-language search query
limitnumber5Maximum results to return

Returns: Array of { title, content, similarity }

Environment Variables

These are read from process.env on the Consumer (not from V8 context variables):

VariableRequiredDescription
ASSISTANT_WORKFLOW_ORG_IDYesOrganization ID for the assistant system workflow
ASSISTANT_WORKFLOW_ENV_IDYesEnvironment ID for the assistant system workflow
ADMIN_API_URLYesBase URL for the admin API (e.g., https://console.rocketwavelabs.io)
ADMIN_SERVICE_TOKENYesBearer token for authenticating MCP calls
OPENAI_VECTOR_API_KEYYesOpenAI API key for vector store search
OPENAI_VECTOR_STORE_IDYesOpenAI vector store ID

How It Works

  1. The upstream Prompt entity generates a JSON research plan using latestPromptResponseJson()
  2. executeResearchPlan() reads the plan and:
    • Validates the assistant context (org/env guard)
    • Executes all mcpCalls in the plan (scoped to the client org/env)
    • Executes all vectorQueries in the plan
  3. Results are stored as V8 globals for downstream entities to use

Research Plan Format

The upstream prompt generates a plan like:

{
"intent": "list_workflows",
"reasoning": "User wants to see their workflows",
"navigationSuggestion": { "page": "workflows" },
"mcpCalls": [
{
"id": "workflows",
"method": "GET",
"path": "/api/workflows",
"params": { "limit": "10" }
}
],
"vectorQueries": [
{
"id": "docs",
"query": "how to create workflows",
"limit": 3
}
]
}