Class: Legion::LLM::Pipeline::Executor

Constant Summary collapse

STEPS =
%i[
  tracing_init idempotency conversation_uuid context_load
  rbac classification billing gaia_advisory tier_assignment rag_context trigger_match skill_injector tool_discovery
  routing request_normalization token_budget provider_call response_normalization metering
  debate confidence_scoring tool_calls context_store post_response knowledge_capture response_return
].freeze
PRE_PROVIDER_STEPS =
%i[
  tracing_init idempotency conversation_uuid context_load
  rbac classification billing gaia_advisory tier_assignment rag_context trigger_match skill_injector tool_discovery
  routing request_normalization token_budget
].freeze
POST_PROVIDER_STEPS =
%i[
  response_normalization metering debate confidence_scoring tool_calls context_store post_response knowledge_capture response_return
].freeze
ASYNC_SAFE_STEPS =
%i[post_response knowledge_capture response_return].freeze
MAX_RUBY_LLM_TOOL_ROUNDS =
200
ASYNC_THREAD_POOL =
Concurrent::FixedThreadPool.new(4, fallback_policy: :caller_runs)

Constants included from Steps::Debate

Steps::Debate::CHALLENGER_PROMPT, Steps::Debate::JUDGE_PROMPT, Steps::Debate::REBUTTAL_PROMPT

Constants included from Steps::ToolCalls

Steps::ToolCalls::MAX_TOOL_LOOPS

Constants included from Steps::Classification

Steps::Classification::LEVELS, Steps::Classification::PHI_KEYWORDS, Steps::Classification::PII_PATTERNS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Steps::Metering

build_event, flush_spool, identity_fields, publish_event, publish_or_spool, timing_and_context, token_fields

Methods included from Steps::Debate

#debate_enabled?, #gaia_debate_trigger?, #run_debate, #step_debate

Methods included from Steps::PromptCache

#apply_cache_control, #apply_conversation_breakpoint, #sort_tools_deterministically

Methods included from Steps::TokenBudget

#step_token_budget

Methods included from Steps::ConfidenceScoring

#step_confidence_scoring

Methods included from Steps::KnowledgeCapture

#step_knowledge_capture

Methods included from Steps::ToolCalls

#step_tool_calls

Methods included from Steps::ToolDiscovery

#step_tool_discovery

Methods included from Steps::SkillInjector

#step_skill_injector

Methods included from Steps::TriggerMatch

#step_trigger_match

Methods included from Steps::RagContext

#step_rag_context

Methods included from Steps::PostResponse

#step_post_response

Methods included from Steps::GaiaAdvisory

#build_partner_context, #step_gaia_advisory

Methods included from Steps::Billing

#step_billing

Methods included from Steps::Classification

#step_classification

Methods included from Steps::Rbac

#step_rbac

Constructor Details

#initialize(request) ⇒ Executor

Returns a new instance of Executor.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/legion/llm/pipeline/executor.rb', line 56

def initialize(request)
  @request = request
  @profile = Profile.derive(request.caller)
  @timeline = Timeline.new
  @tracing = nil
  @enrichments = {}
  @audit = {}
  @warnings = []
  @timestamps = { received: Time.now }
  @raw_response = nil
  @exchange_id = nil
  @discovered_tools = []
  @triggered_tools = []
  @resolved_provider = nil
  @resolved_model = nil
  @confidence_score = nil
  @escalation_chain = nil
  @escalation_history = []
  @proactive_tier_assignment = nil
  @tool_event_handler = nil
end

Instance Attribute Details

#auditObject (readonly)

Returns the value of attribute audit.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def audit
  @audit
end

#confidence_scoreObject (readonly)

Returns the value of attribute confidence_score.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def confidence_score
  @confidence_score
end

#discovered_toolsObject (readonly)

Returns the value of attribute discovered_tools.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def discovered_tools
  @discovered_tools
end

#enrichmentsObject (readonly)

Returns the value of attribute enrichments.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def enrichments
  @enrichments
end

#escalation_chainObject (readonly)

Returns the value of attribute escalation_chain.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def escalation_chain
  @escalation_chain
end

#profileObject (readonly)

Returns the value of attribute profile.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def profile
  @profile
end

#requestObject (readonly)

Returns the value of attribute request.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def request
  @request
end

#timelineObject (readonly)

Returns the value of attribute timeline.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def timeline
  @timeline
end

#tool_event_handlerObject

Returns the value of attribute tool_event_handler.



20
21
22
# File 'lib/legion/llm/pipeline/executor.rb', line 20

def tool_event_handler
  @tool_event_handler
end

#tracingObject (readonly)

Returns the value of attribute tracing.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def tracing
  @tracing
end

#warningsObject (readonly)

Returns the value of attribute warnings.



17
18
19
# File 'lib/legion/llm/pipeline/executor.rb', line 17

def warnings
  @warnings
end

Instance Method Details

#callObject



78
79
80
81
# File 'lib/legion/llm/pipeline/executor.rb', line 78

def call
  execute_steps
  build_response
end

#call_stream(&block) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/legion/llm/pipeline/executor.rb', line 83

def call_stream(&block)
  return call unless block

  execute_pre_provider_steps
  step_provider_call_stream(&block)
  execute_post_provider_steps
  build_response
end