refactor: use the new prompt rendere
This commit is contained in:
@@ -69,9 +69,39 @@ class Captain::Assistant < ApplicationRecord
|
||||
}
|
||||
end
|
||||
|
||||
def agent(user)
|
||||
# Get enabled scenario agents as handoff agents
|
||||
handoff_agents = scenarios.enabled.map { |scenario| scenario.agent(user) }
|
||||
|
||||
# Create the main assistant agent with scenario agents as handoffs
|
||||
Agents::Agent.new(
|
||||
name: name,
|
||||
instructions: agent_instructions,
|
||||
handoff_agents: handoff_agents
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def agent_instructions
|
||||
Captain::PromptRenderer.render('assistant', prompt_context)
|
||||
end
|
||||
|
||||
def prompt_context
|
||||
{
|
||||
name: name,
|
||||
description: description,
|
||||
product_name: config['product_name'] || 'this product',
|
||||
scenarios: scenarios.enabled.map do |scenario|
|
||||
{
|
||||
key: scenario.title.parameterize.underscore,
|
||||
description: scenario.description
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def default_avatar_url
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/assets/images/dashboard/captain/logo.svg"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -40,19 +40,15 @@ class Captain::Scenario < ApplicationRecord
|
||||
before_save :resolve_tool_references
|
||||
|
||||
def agent_instructions
|
||||
instructions = <<~INSTRUCTIONS
|
||||
You are a specialized agent in a multiagent system. Your job is to assist the primary agent in completing tasks.
|
||||
Here's your instructions:
|
||||
Captain::PromptRenderer.render('scenario', prompt_context)
|
||||
end
|
||||
|
||||
#{resolved_instructions}
|
||||
INSTRUCTIONS
|
||||
|
||||
if resolved_tools.any?
|
||||
instructions += "\n\nYou have access to the following tools:\n"
|
||||
instructions += resolved_tools.map { |tool| "- #{tool[:id]}: #{tool[:description]}" }.join("\n")
|
||||
end
|
||||
|
||||
instructions
|
||||
def prompt_context
|
||||
{
|
||||
title: title,
|
||||
instructions: resolved_instructions,
|
||||
tools: resolved_tools
|
||||
}
|
||||
end
|
||||
|
||||
def agent_tools
|
||||
|
||||
Reference in New Issue
Block a user