src.ai.providers.llm_abstraction module#
LLM Abstraction Layer for Marcus AI.
Provides a unified interface across different LLM providers (Anthropic, OpenAI, local models) with intelligent fallback and provider switching capabilities.
This module implements the strategy pattern for LLM providers, allowing seamless switching between providers and automatic fallback on failures.
Classes#
- LLMAbstraction
Multi-provider LLM abstraction with intelligent fallback
Notes
Provider selection is controlled by the MARCUS_LLM_PROVIDER environment variable. The system automatically falls back to alternative providers on failure.
Examples
>>> llm = LLMAbstraction()
>>> analysis = await llm.analyze_task_semantics(task, context)
>>> if analysis.fallback_used:
... print("Using fallback provider")
- class src.ai.providers.llm_abstraction.LLMAbstraction[source]#
Bases:
objectMulti-provider LLM abstraction with intelligent fallback.
Supports multiple LLM providers with automatic fallback when primary fails. Provides a unified interface for all AI operations in Marcus.
- analyze_task_semantics(task, context)[source]#
Analyze task meaning and intent
- Parameters:
- Return type:
- infer_dependencies_semantic(tasks)[source]#
Infer logical dependencies between tasks
- Parameters:
- Return type:
- estimate_effort_intelligently(task, context)[source]#
AI-powered effort estimation
- Parameters:
- Return type:
- analyze_blocker_and_suggest_solutions(task, blocker, severity, agent)[source]#
Analyze blockers and provide solutions
Notes
Providers are initialized lazily to avoid circular imports. Statistics are tracked for intelligent provider selection.
- async analyze_task_semantics(task, context)[source]#
Analyze task semantics using the best available provider.
- Parameters:
- Returns:
Comprehensive semantic analysis including intent and risks
- Return type:
Notes
Automatically falls back to alternative providers on failure. Tagged
analyze_task_semanticsvia_tagged_operation()so the resultingtoken_events.operationrow carries that label instead of the provider’s default.
- async infer_dependencies_semantic(tasks)[source]#
Infer semantic dependencies between tasks.
- Parameters:
- Returns:
Inferred logical relationships between tasks
- Return type:
Notes
Complements rule-based dependency detection with semantic understanding. Tagged
infer_dependenciesvia_tagged_operation().
- async estimate_effort_intelligently(task, context)[source]#
Estimate task effort using AI.
- Parameters:
- Returns:
AI-powered time estimate with confidence and factors
- Return type:
- async analyze_blocker_and_suggest_solutions(task, blocker_description, severity, agent)[source]#
Analyze a blocker and suggest solutions.
- Parameters:
- Returns:
Prioritized list of solution suggestions
- Return type:
Notes
Higher severity blockers receive more detailed analysis.
- async analyze(prompt, context, *, operation=None)[source]#
Analyze content using LLM.
- Parameters:
prompt (
str) – The prompt to analyze.context (
Any) – Analysis context (may carrymax_tokensoverride).operation (
Optional[str]) – Logical operation label to attach to the cost event. When provided, the recorder’s active PlannerContext is shadowed with anoperation_overridefor the duration of the call, sotoken_events.operationrecordsoperationinstead of whatever default the provider stamps. Used for per-call drill-down in the Cato cost dashboard. Seesrc/cost_tracking/operations.pyfor the canonical taxonomy and human-readable descriptions.
- Returns:
Analysis result as string.
- Return type: