The Context & Dependency System is one of Marcus's core intelligence subsystems, responsible for providing rich contextual information to agents and inferring dependencies between tasks to prevent illogical assignments. This system transforms Marcus from a simple task dispatcher into an intelligent project coordination platform that understands relationships, learns from patterns, and adapts to different project structures.
The Context & Dependency System serves multiple critical functions:
- Task Context Generation: Provides agents with rich context including previous implementations, dependent tasks, related patterns, and architectural decisions
- Dependency Inference: Automatically identifies logical dependencies between tasks using multiple strategies (pattern-based, AI-enhanced, and adaptive learning)
- Architectural Decision Tracking: Maintains a history of decisions made by agents to inform future work
- Task Ordering Optimization: Suggests optimal task execution order based on dependencies and priorities
- Pattern Learning: Learns from project completions and user feedback to improve future recommendations
The system consists of several interconnected components:
┌─────────────────────────────────────────────────────────────┐
│ Context & Dependency System │
├─────────────────┬──────────────────┬─────────────────────────┤
│ Core Context │ Dependency │ Detection & │
│ Management │ Inference │ Analysis │
│ │ │ │
│ • Context │ • DependencyIn- │ • ContextDetector │
│ • TaskContext │ ferer (Base) │ • BoardAnalyzer │
│ • Decision │ • HybridDepen- │ • AdaptiveDependen- │
│ • DependentTask │ dencyInferer │ cyInferer │
│ │ • DependencyGraph│ │
└─────────────────┴──────────────────┴─────────────────────────┘
- Context: Main orchestrator class that manages all context operations
- TaskContext: Complete context package for task assignments
- Decision: Architectural decision tracking
- DependentTask: Information about task dependencies
- DependencyInferer: Base pattern-based dependency inference
- DependencyPattern: Rule definitions for common dependency patterns
- InferredDependency: Dependency relationship with confidence scoring
- DependencyGraph: Graph representation with cycle detection
- HybridDependencyInferer: Combines patterns with AI analysis
- HybridDependency: Enhanced dependency with multiple inference methods
- Intelligent caching and batch processing for AI calls
- AdaptiveDependencyInferer: Learns from user feedback and board state
- RelationshipPattern: User-defined and learned patterns
- DependencySignal: Multiple weak signals combined for inference
- WorkflowPattern: Domain-specific workflow templates
- ContextDetector: Determines optimal Marcus mode based on board state
- MarcusMode: Creator, Enricher, or Adaptive modes
- UserIntent: Intent detection from user messages
The Context system publishes events for:
IMPLEMENTATION_FOUND: When new implementation context is addedDECISION_LOGGED: When architectural decisions are recordedCONTEXT_UPDATED: When task context is generated
- Stores decisions and implementations for long-term learning
- Graceful degradation when persistence is unavailable
- Supports various persistence backends
- Uses Claude/AI engines for complex dependency inference
- Implements intelligent caching to minimize API calls
- Fallback to pattern-based inference when AI is unavailable
- Exposes context functionality through MCP tools
- The only registered MCP context tool is
get_task_contextfor detailed task information analyze_dependenciesis an internal method on theContextclass, not an MCP tool
In the typical Marcus workflow, the Context & Dependency System is invoked at these points:
create_project → register_agent → [CONTEXT ANALYSIS] → request_next_task →
[DEPENDENCY CHECK] → report_progress → [DECISION TRACKING] → report_blocker →
[CONTEXT UPDATE] → finish_task → [PATTERN LEARNING]
- Analyzes board state to determine optimal Marcus mode
- Provides recommendations for project structure
- Establishes context tracking for the agent
- Initializes dependency inference capabilities
- Primary Integration Point: Generates rich context for task assignments
- Analyzes dependencies to ensure logical task ordering
- Provides implementation patterns from previous work
- Tracks implementation details for future context
- Records architectural decisions
- Updates dependency relationships
- Uses context to suggest solutions based on previous implementations
- Analyzes dependency chains to identify root causes
- Extracts patterns for future use
- Updates confidence scores based on successful completions
- Feeds learning back into the system
Unlike simple rule-based systems, Marcus employs three complementary strategies:
- Pattern-Based: Fast, deterministic rules for common cases
- AI-Enhanced: Sophisticated analysis for complex scenarios
- Adaptive Learning: Learns from user feedback and project outcomes
The system maintains functionality even when components are unavailable:
- Falls back to patterns when AI is unavailable
- Continues working without persistence
- Provides basic context even without previous implementations
Each task assignment includes:
- Previous Implementations: What other agents have built
- Dependent Tasks: What depends on this work
- Related Patterns: Similar work done before
- Architectural Decisions: Relevant decisions that affect this task
- Caches AI inference results to minimize costs
- Uses content-based cache keys for consistency
- Implements TTL for cache freshness
# Example patterns from dependency_inferer.py
DependencyPattern(
name="testing_before_deployment",
description="Testing must complete before deployment",
condition_pattern=r"(deploy|release|launch|production)",
dependency_pattern=r"(test|qa|quality|verify)",
confidence=0.95,
mandatory=True
)# Batch analysis for ambiguous cases
prompt = f"""Analyze these task pairs and determine dependencies.
A dependency exists if one task must be completed before another.
Task pairs to analyze: {json.dumps(pairs_to_analyze, indent=2)}
Return JSON with dependency direction and reasoning."""# Learning from user corrections
def record_feedback(self, task_a_id, task_b_id, is_dependency,
original_confidence, user_confirmed, reason=None):
# Adjust feature weights based on feedback
# Learn new patterns from confirmed dependencies
# Update confidence thresholds@dataclass
class TaskContext:
task_id: str
previous_implementations: Dict[str, Any] # From completed tasks
dependent_tasks: List[Dict[str, Any]] # Tasks depending on this
related_patterns: List[Dict[str, Any]] # Similar previous work
architectural_decisions: List[Dict[str, Any]] # Relevant decisions@dataclass
class Decision:
decision_id: str
task_id: str
agent_id: str
timestamp: datetime
what: str # What was decided
why: str # Why it was decided
impact: str # Impact on other components- Only uses AI for ambiguous cases identified by pattern analysis
- Batches multiple inferences into single API calls
- Implements exponential backoff for API failures
- Automatic cleanup of old context data
- Configurable retention periods
- Efficient graph algorithms for cycle detection
- Content-based cache keys for consistency
- TTL-based expiration for freshness
- Memory-efficient storage of inference results
For straightforward dependencies like "test after implement":
- Fast pattern matching (< 1ms)
- High confidence scores (0.9+)
- Deterministic results
- No AI calls required
For ambiguous relationships:
- Initial pattern screening
- AI analysis for unclear cases
- Confidence combination from multiple sources
- Learning from user feedback
The system adapts its complexity based on:
- Board maturity: More sophisticated analysis for larger projects
- User feedback: Learns domain-specific patterns
- Project type: Different strategies for different domains
- Minimal context available
- Focus on high-level architectural patterns
- Recommend Creator mode for structure generation
- High dependency inference activity
- Pattern learning from existing relationships
- Recommend Enricher mode for organization
- Leverage existing metadata and relationships
- Optimize for agent coordination
- Recommend Adaptive mode for efficiency
The system considers board quality metrics:
- Structure Score: Influences inference confidence
- Metadata Completeness: Affects context richness
- Dependency Clarity: Determines analysis depth
- Reads explicit dependencies from Cato board
- Suggests new dependencies through Marcus interface
- Respects user-defined relationships as ground truth
- Enriches Cato tasks with inferred relationships
- Adds confidence scores for suggested dependencies
- Provides reasoning for all inferences
- Respects user settings for inference aggressiveness
- Allows disabling of automatic inference
- Provides manual override capabilities
- Combines speed of patterns with intelligence of AI
- Graceful degradation ensures reliability
- Learns and adapts from user feedback
- Provides agents with comprehensive background
- Reduces time spent understanding existing code
- Enables better integration between agent work
- Minimizes AI API costs through caching
- Efficient pattern matching for common cases
- Scales gracefully with project size
- Respects user preferences and explicit relationships
- Provides clear reasoning for all inferences
- Allows easy override of system suggestions
- Multiple inference strategies increase maintenance burden
- Cache management adds complexity
- Error handling across multiple failure modes
- Reduced functionality when AI services are unavailable
- Potential latency for complex inference operations
- Cost implications for large-scale usage
- Multiple modes and settings may confuse new users
- Requires understanding of confidence thresholds
- Pattern configuration may be intimidating
- Graph algorithms may not scale to very large projects
- Memory usage grows with project history
- Cache invalidation complexity
Traditional task management systems lack understanding of task relationships, leading to:
- Illogical task assignments (testing before implementation)
- Agents working without context of previous decisions
- Repeated work due to lack of pattern recognition
- Poor coordination between distributed agents
- Use simple patterns for obvious cases
- Apply AI only where needed
- Learn from real user behavior
- System remains functional when components fail
- Multiple fallback strategies
- No single point of failure
- Users remain in control of their project structure
- System provides suggestions, not mandates
- Easy override of system decisions
- Minimize external API calls
- Cache aggressively
- Optimize for common cases
- Rejected: Too rigid for diverse project types
- Problem: Can't handle edge cases or domain-specific patterns
- Rejected: Too expensive and unreliable
- Problem: Latency and cost issues for all decisions
- Rejected: Places too much burden on users
- Problem: Most users don't specify comprehensive dependencies
- Rejected: Too simplistic for complex projects
- Problem: High false positive/negative rates
- Multi-Model Ensemble: Combine different AI models for robustness
- Domain-Specific Models: Fine-tuned models for different project types
- Real-Time Learning: Continuous learning from user interactions
- Natural Language Processing: Better extraction of semantics from task descriptions
- Code Analysis Integration: Analyze actual code to infer technical dependencies
- Temporal Pattern Recognition: Learn from timing patterns in project completion
- Visual Dependency Editor: Graphical interface for dependency management
- Confidence Explanations: Detailed explanations of inference reasoning
- Interactive Learning: Real-time feedback incorporation
- Distributed Processing: Scale to very large projects
- Incremental Updates: Efficient updates for changing project state
- Predictive Caching: Anticipate needed context before requests
- Code Context: Integration with version control systems
- Communication Context: Learn from team chat and comments
- Performance Context: Track task completion times and success rates
- Multiple Board Support: Work across multiple Kanban boards
- External Tool Integration: Context from JIRA, GitHub, etc.
- Team Collaboration: Shared context across team members
The Context & Dependency System represents a sophisticated approach to project intelligence that balances automation with user control, performance with accuracy, and simplicity with power. By providing rich context to agents and intelligently inferring relationships between tasks, it transforms Marcus from a simple coordinator into an intelligent project partner that learns and adapts to each team's unique workflow patterns.
The system's multi-strategy approach ensures reliable operation across diverse scenarios while its adaptive learning capabilities enable continuous improvement. As projects evolve and teams provide feedback, the system becomes increasingly valuable, making it a cornerstone of Marcus's intelligent project management capabilities.