From bdd5a77f45f92e4f2ad874fff917e43b69c1fe78 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 9 Jul 2025 18:22:29 +0530 Subject: [PATCH] feat: add agent instructions --- enterprise/app/models/captain/scenario.rb | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/enterprise/app/models/captain/scenario.rb b/enterprise/app/models/captain/scenario.rb index e6b989073..de9474561 100644 --- a/enterprise/app/models/captain/scenario.rb +++ b/enterprise/app/models/captain/scenario.rb @@ -39,8 +39,39 @@ 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: + + #{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 + end + private + def resolved_instructions + instruction.gsub(%r{\(tool://(\w+)\)}) do |match| + "#{match} tool " + end + end + + def resolved_tools + return [] if tools.blank? + + available_tools = self.class.available_agent_tools + tools.filter_map do |tool_id| + available_tools.find { |tool| tool[:id] == tool_id } + end + end + # Validates that all tool references in the instruction are valid. # Parses the instruction for tool references and checks if they exist # in the available tools configuration.