feat: add campaign context to Captain v2 prompts (#13644)

Co-authored-by: Aakash Bakhle <48802744+aakashb95@users.noreply.github.com>
This commit is contained in:
Shivam Mishra
2026-02-25 18:33:37 +05:30
committed by GitHub
parent ba804e0f30
commit b98c614669
7 changed files with 83 additions and 5 deletions

View File

@@ -19,9 +19,11 @@ module Concerns::Agentable
state = context.context[:state] || {}
conversation_data = state[:conversation] || {}
contact_data = state[:contact] || {}
campaign_data = state[:campaign] || {}
enhanced_context = enhanced_context.merge(
conversation: conversation_data,
contact: contact_data
contact: contact_data,
campaign: campaign_data
)
end

View File

@@ -16,6 +16,8 @@ class Captain::Assistant::AgentRunnerService
custom_attributes additional_attributes
].freeze
CAMPAIGN_STATE_ATTRIBUTES = %i[id title message campaign_type description].freeze
def initialize(assistant:, conversation: nil, callbacks: {})
@assistant = assistant
@conversation = conversation
@@ -129,6 +131,7 @@ class Captain::Assistant::AgentRunnerService
state[:conversation] = @conversation.attributes.symbolize_keys.slice(*CONVERSATION_STATE_ATTRIBUTES)
state[:channel_type] = @conversation.inbox&.channel_type
state[:contact] = @conversation.contact.attributes.symbolize_keys.slice(*CONTACT_STATE_ATTRIBUTES) if @conversation.contact
state[:campaign] = @conversation.campaign.attributes.symbolize_keys.slice(*CAMPAIGN_STATE_ATTRIBUTES) if @conversation.campaign
end
state

View File

@@ -8,7 +8,7 @@ You are {{name}}, a helpful and knowledgeable assistant. Your role is to primari
Don't digress away from your instructions, and use all the available tools at your disposal for solving customer issues. If you are to state something factual about {{product_name}} ensure you source that information from the FAQs only. Use the `captain--tools--faq_lookup` tool for this.
{% if conversation || contact -%}
{% if conversation || contact || campaign.id -%}
# Current Context
Here's the metadata we have about the current conversation and the contact associated with it:
@@ -20,6 +20,10 @@ Here's the metadata we have about the current conversation and the contact assoc
{% if contact -%}
{% render 'contact' %}
{% endif -%}
{% if campaign.id -%}
{% render 'campaign' %}
{% endif -%}
{% endif -%}
{% if response_guidelines.size > 0 -%}

View File

@@ -8,7 +8,7 @@ You are a specialized agent called "{{ title }}", your task is to handle the fol
If you believe the user's request is not within the scope of your role, you can assign this conversation back to the orchestrator agent using the `handoff_to_{{ assistant_name }}` tool
{% if conversation || contact %}
{% if conversation || contact || campaign.id %}
# Current Context
Here's the metadata we have about the current conversation and the contact associated with it:
@@ -20,6 +20,10 @@ Here's the metadata we have about the current conversation and the contact assoc
{% if contact -%}
{% render 'contact' %}
{% endif -%}
{% if campaign.id -%}
{% render 'campaign' %}
{% endif -%}
{% endif -%}

View File

@@ -0,0 +1,8 @@
# Campaign Context
This conversation was initiated in response to a campaign message.
- Campaign: {{ campaign.title }}
- Type: {{ campaign.campaign_type }}
{% if campaign.description -%}
- Description: {{ campaign.description }}
{% endif -%}
- Original Message Sent: {{ campaign.message }}