Skip to content

feat: Add multi-prompt stage support per assistant #88

Open
AasheeshLikePanner wants to merge 6 commits into
rapidaai:mainfrom
AasheeshLikePanner:feat/multi-prompt-stages
Open

feat: Add multi-prompt stage support per assistant #88
AasheeshLikePanner wants to merge 6 commits into
rapidaai:mainfrom
AasheeshLikePanner:feat/multi-prompt-stages

Conversation

@AasheeshLikePanner

Copy link
Copy Markdown

Description
Enables a single assistant to use different system prompts at different conversation stages. This addresses the use case where a bot needs to function in steps - e.g., first verify user identity with one prompt, then handle order placement with a different prompt.

Type of Change

  • New feature (non-breaking change that adds functionality)

Related Issues


Checklist
General

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's coding standards
  • I have performed a self-review of my code
    Testing
  • Unit tests pass (2 tests added)
  • Database migration tested
  • E2E flow verified via SQL simulation
    Documentation
  • Documentation update (can be added in follow-up)
    Security
  • No sensitive data committed

Additional Notes

  • Backend implementation complete; API/UI for stage management can be added in follow-up PRs
  • Built-in transition_stage tool available for LLM to trigger stage changes

- Add AssistantPromptStage entity for storing multiple prompts per assistant
- Add current_stage_id to conversations for tracking current stage
- Add service methods for CRUD operations on prompt stages
- Add stage template selection in LLM executor
- Add database migration for prompt_stages table

This enables step-based behavior where bot can use different system
prompts at different conversation stages (e.g., identity_check ->
order_placement). Stage transitions can be triggered via tool calls.
…ai#72)

- Add built-in transition_stage tool that LLM can call to switch stages
- Add stage_transition_caller that emits directive packets
- Add handleStageTransition in dispatch to process stage changes
- Update conversation.current_stage_id when transition is requested

Now the bot can automatically transition between prompts:
1. LLM calls transition_stage(stage_name='order_placement')
2. Tool emits directive packet with transition_stage arg
3. Dispatcher processes and updates conversation stage
4. Next LLM request uses the new stage's prompt
@AasheeshLikePanner AasheeshLikePanner changed the title feat: Add multi-prompt stage support per assistant (#72) feat: Add multi-prompt stage support per assistant Mar 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces “prompt stages” to support multi-step assistants by allowing different system prompts to be used at different points in a conversation, with a built-in tool to transition between stages.

Changes:

  • Adds DB schema for assistant_prompt_stages and tracks current_stage_id on assistant_conversations.
  • Adds assistant-service CRUD methods for prompt stages and a method to update the conversation’s current stage.
  • Registers a built-in transition_stage tool and adds stage-selection logic in the LLM executor + adapter dispatch path.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
api/assistant-api/migrations/000012_add_prompt_stages.up.sql Creates prompt stage table and adds current_stage_id to conversations.
api/assistant-api/migrations/000012_add_prompt_stages.down.sql Rolls back the prompt stage table and conversation column.
api/assistant-api/internal/services/assistant/assistant.impl.service.go Implements prompt stage CRUD + conversation stage update in AssistantService.
api/assistant-api/internal/services/assistant.service.go Extends AssistantService interface with prompt-stage methods.
api/assistant-api/internal/entity/conversations/conversation.assistant.go Adds CurrentStageId field to the conversation entity.
api/assistant-api/internal/entity/assistants/prompt_stage.assistant.go Adds AssistantPromptStage entity + template setter/getter.
api/assistant-api/internal/entity/assistants/prompt_stage_test.go Adds unit tests around prompt stage template parsing behavior.
api/assistant-api/internal/agent/executor/tool/tool.go Registers the built-in transition_stage tool.
api/assistant-api/internal/agent/executor/tool/internal/local/stage_transition_caller.go Implements the stage transition tool caller.
api/assistant-api/internal/agent/executor/llm/internal/model/model.go Adds stage-based prompt selection logic (via cached templates).
api/assistant-api/internal/adapters/internal/dispatch.go Hooks stage transitions into directive handling and updates conversation stage.
Comments suppressed due to low confidence (1)

api/assistant-api/internal/adapters/internal/dispatch.go:839

  • Even when the directive contains transition_stage, this code still notifies ConversationDirective_END_CONVERSATION to the client/stream. That will terminate the conversation while also switching the stage, which is likely unintended. Stage transitions should not be routed through the END_CONVERSATION directive path (handle them separately and skip the end-conversation notification).
	case protos.ConversationDirective_END_CONVERSATION:
		// Check for stage transition request
		if stageName, ok := vl.Arguments["transition_stage"].(string); ok && stageName != "" {
			talking.handleStageTransition(ctx, vl.ContextID, stageName)
		}
		if err := talking.Notify(ctx, &protos.ConversationDirective{
			Id:   vl.ContextID,
			Type: vl.Directive,
			Args: anyArgs,
			Time: timestamppb.Now(),
		}); err != nil {

Comment thread api/assistant-api/internal/agent/executor/llm/internal/model/model.go Outdated
Comment thread api/assistant-api/migrations/000012_add_prompt_stages.up.sql Outdated
Comment thread api/assistant-api/internal/services/assistant/assistant.impl.service.go Outdated
Comment thread api/assistant-api/internal/services/assistant/assistant.impl.service.go Outdated
Comment thread api/assistant-api/internal/services/assistant/assistant.impl.service.go Outdated
Comment thread api/assistant-api/internal/services/assistant/assistant.impl.service.go Outdated
Comment thread api/assistant-api/internal/services/assistant/assistant.impl.service.go Outdated
Comment thread api/assistant-api/internal/adapters/internal/dispatch.go
Comment thread api/assistant-api/internal/entity/assistants/prompt_stage_test.go Outdated
- Fix migration column names (created_date/updated_date, order)
- Add schema qualification (public.*) for consistency
- Use clause.OrderByColumn instead of backticks for PostgreSQL
- Set audit fields (CreatedBy, UpdatedBy, Status) on stage creation/update
- Use soft delete instead of hard delete for DeletePromptStage
- Return proper error when no stages found in GetDefaultPromptStage
- Add auth scoping to UpdateConversationStage for tenant safety
- Fix SetPrompt to return error for invalid JSON
- Update in-memory conversation after stage transition
- Use ConversationEventPacket instead of END_CONVERSATION to avoid ending conversation
- Use communication.GetMetadata() to get stage_template in executor
- Set stage_template in requestor metadata after stage transition
- Simplify executor template lookup to use metadata only
- Use 'prompt' instead of 'text_chat_complete'
- Use 'promptVariables' instead of 'variables'
- Use 'defaultValue' instead of 'default'
- Update tests to check for error return from SetPrompt
- Use stage.Template.GetTextChatCompleteTemplate() instead of stage.GetTemplate()
- Add gorm_types import to dispatch.go
- Template now correctly passed as *TextChatCompletePromptTemplate to executor
@iamprashant

Copy link
Copy Markdown
Member

@AasheeshLikePanner Please update the branch with new changes.

@AasheeshLikePanner

AasheeshLikePanner commented Mar 25, 2026

Copy link
Copy Markdown
Author

@iamprashant I’ve pulled the latest changes from main. This branch is up to date and ready to merge.

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]: Does it support Multi Prompts per Assistant Support

3 participants