Class: Legion::LLM::Inference::Executor

Defined Under Namespace

Classes: ToolResultEvent

Constant Summary collapse

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

Constants included from Steps::StickyPersist

Steps::StickyPersist::SENSITIVE_PARAM_NAMES

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, Steps::Classification::PII_PATTERNS_CORE, Steps::Classification::PII_PATTERNS_EXTENDED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Steps::StickyPersist

#step_sticky_persist

Methods included from Steps::ToolHistory

#step_tool_history_inject

Methods included from Steps::StickyRunners

#step_sticky_runners

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.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/legion/llm/inference/executor.rb', line 58

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
  @resolved_offering_id = nil
  @resolved_offering_metadata = {}
  @confidence_score = nil
  @escalation_chain = nil
  @escalation_history = []
  @proactive_tier_assignment = nil
  @tool_event_handler = nil
  @sticky_turn_snapshot = nil
  @pending_tool_history = Concurrent::Array.new
  @pending_tool_history_mutex = Mutex.new
  @injected_tool_map = {}
  @native_tool_source_map = {}
  @freshly_triggered_keys = []
end

Instance Attribute Details

#auditObject (readonly)

Returns the value of attribute audit.



17
18
19
# File 'lib/legion/llm/inference/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/inference/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/inference/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/inference/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/inference/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/inference/executor.rb', line 17

def profile
  @profile
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

#timelineObject (readonly)

Returns the value of attribute timeline.



17
18
19
# File 'lib/legion/llm/inference/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/inference/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/inference/executor.rb', line 17

def tracing
  @tracing
end

#warningsObject (readonly)

Returns the value of attribute warnings.



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

def warnings
  @warnings
end

Instance Method Details

#callObject



88
89
90
91
# File 'lib/legion/llm/inference/executor.rb', line 88

def call
  execute_steps
  build_response
end

#call_stream(&block) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/legion/llm/inference/executor.rb', line 93

def call_stream(&block)
  return call unless block

  execute_pre_provider_steps
  step_provider_call_stream(&block)
  execute_post_provider_steps
  build_response
end