Class: AgentEvalPlanner::ContractAnalyzer
- Inherits:
-
Object
- Object
- AgentEvalPlanner::ContractAnalyzer
- Defined in:
- lib/agent_eval_planner/contract_analyzer.rb
Overview
Parses an agent contract file (markdown/text/JSON/YAML) into a structured profile.
Constant Summary collapse
- TOOL_LINE_RE =
/ ^\s*[-*]\s*`?([a-z][a-z0-9_]*)`?\s*$| ^\s*[-*]\s*tool[s]?\s*:\s*`?([a-z][a-z0-9_]*)`?| ^\s*`([a-z][a-z0-9_]*)`\s*[—(]\s*tool /ix- TOOLS_INLINE_RE =
/tools?\s*[:=]\s*\[([^\]]+)\]/i- NAME_RE =
Use %r so a literal "/" inside the character class does not terminate the regexp.
%r{(?:agent(?:\s+name)?|specialist|target[_ ]?agent)\s*[:=]\s*["']?([A-Za-z0-9_\-./]+)["']?}i
Instance Attribute Summary collapse
-
#agent_name ⇒ Object
readonly
Returns the value of attribute agent_name.
-
#declared_scope ⇒ Object
readonly
Returns the value of attribute declared_scope.
-
#harness ⇒ Object
readonly
Returns the value of attribute harness.
-
#out_of_scope ⇒ Object
readonly
Returns the value of attribute out_of_scope.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#signals ⇒ Object
readonly
Returns the value of attribute signals.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #analytics_domain? ⇒ Boolean
- #has_tools? ⇒ Boolean
-
#initialize(source_path: nil, raw: nil, agent_name: nil, tools: nil, declared_scope: nil, out_of_scope: nil, harness: "generic") ⇒ ContractAnalyzer
constructor
A new instance of ContractAnalyzer.
- #introduction ⇒ Object
- #multi_specialist? ⇒ Boolean
Constructor Details
#initialize(source_path: nil, raw: nil, agent_name: nil, tools: nil, declared_scope: nil, out_of_scope: nil, harness: "generic") ⇒ ContractAnalyzer
Returns a new instance of ContractAnalyzer.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 22 def initialize( source_path: nil, raw: nil, agent_name: nil, tools: nil, declared_scope: nil, out_of_scope: nil, harness: "generic" ) @source_path = source_path @raw = raw || read_source!(source_path) @agent_name = agent_name || extract_agent_name || "default" @tools = normalize_tools(tools || extract_tools) @declared_scope = declared_scope || extract_scope_hint || "Escopo declarado no contrato do agente" @out_of_scope = out_of_scope || "Pedidos off-topic, assistente geral, conteúdo fora do domínio" @harness = harness || "generic" @signals = detect_signals end |
Instance Attribute Details
#agent_name ⇒ Object (readonly)
Returns the value of attribute agent_name.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def agent_name @agent_name end |
#declared_scope ⇒ Object (readonly)
Returns the value of attribute declared_scope.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def declared_scope @declared_scope end |
#harness ⇒ Object (readonly)
Returns the value of attribute harness.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def harness @harness end |
#out_of_scope ⇒ Object (readonly)
Returns the value of attribute out_of_scope.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def out_of_scope @out_of_scope end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def raw @raw end |
#signals ⇒ Object (readonly)
Returns the value of attribute signals.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def signals @signals end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def source_path @source_path end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
19 20 21 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 19 def tools @tools end |
Instance Method Details
#analytics_domain? ⇒ Boolean
49 50 51 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 49 def analytics_domain? signals[:analytics] end |
#has_tools? ⇒ Boolean
41 42 43 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 41 def has_tools? !tools.empty? end |
#introduction ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 53 def introduction parts = ["Agente **#{agent_name}**"] parts << "com #{tools.size} tool(s) no contrato" if has_tools? parts << "sem tools declaradas" unless has_tools? parts << "(harness: #{harness})" "#{parts.join(' ')}. Pipeline de eval de guardrails — paralelo do plano de pentest de API, aplicado a comportamento de LLM." end |
#multi_specialist? ⇒ Boolean
45 46 47 |
# File 'lib/agent_eval_planner/contract_analyzer.rb', line 45 def multi_specialist? signals[:multi_specialist] end |