Agency Phase 2 Implementation Summary¶
Date: December 9, 2025
Status: β
COMPLETE
Overview¶
Phase 2 integrates world model context and personality traits into the Agency system, enabling context-aware goal creation with personality-based priority adjustments and relationship-driven proactivity.
β Completed Components¶
1. WorldModelService (shared/aico/ai/world_model/)¶
Purpose: Unified API for querying knowledge graph and semantic memory.
Files Created:
- __init__.py - Package exports
- models.py - Data models (UserContext, Entity, Project, OpenLoop, WorldContext)
- service.py - Service implementation
Key Features:
- β
get_user_context() - Retrieve comprehensive user context
- β
get_entities_around_user() - Get related entities from KG
- β
get_active_projects() - Get user's active projects
- β
get_world_context() - Combined context retrieval
- β
Graceful fallback for missing data
- β
Integration with existing PropertyGraphStorage
Integration Points:
- Uses PropertyGraphStorage.get_user_nodes() for entity queries
- Filters by entity type and recency
- Returns structured context objects
2. PersonalityService (shared/aico/ai/personality/)¶
Purpose: Personality traits and relationship context for agency decisions.
Files Created:
- __init__.py - Package exports
- models.py - Data models (PersonalityTraits, RelationshipVector, PersonalityContext)
- service.py - Service implementation
Key Features:
- β
get_personality_context() - Retrieve personality and relationship data
- β
adjust_priority_for_personality() - Adjust goal priority based on conscientiousness
- β
calculate_proactivity_level() - Calculate proactivity from relationship closeness
- β
Big Five personality traits (extraversion, agreeableness, conscientiousness, neuroticism, openness)
- β
Relationship vectors (closeness, trust, familiarity, proactivity preference)
- β
Lazy logger initialization to avoid import errors
Personality Adjustments: - High conscientiousness (>0.7): Bumps priority up one level (max: high) - Low conscientiousness (<0.3): Reduces priority one level (min: low) - Moderate conscientiousness: No change - Proactivity: Weighted average of relationship closeness (40%) and preference (60%)
3. AgencyEngine Integration (shared/aico/ai/agency/engine.py)¶
New Parameters:
- world_model: Optional[WorldModelService] - World model service instance
- personality_service: Optional[PersonalityService] - Personality service instance
New Methods:
create_goal_with_world_context()¶
Enriches goal metadata with world model context:
- Active projects from knowledge graph
- Related entities (top 5)
- Open loops (WIP: currently a placeholder in WorldModelService.get_open_loops())
- Retrieval timestamp
create_goal_with_full_context() β Recommended Phase 2 Method¶
Combines world model AND personality context: 1. Retrieves personality context 2. Adjusts priority based on conscientiousness 3. Calculates proactivity level 4. Retrieves world model context 5. Enriches metadata with all context 6. Creates goal with adjusted priority
Metadata Enrichment Example:
{
"personality_context": {
"relationship_closeness": 0.5,
"proactivity_level": 0.55,
"priority_adjusted": true,
"original_priority": "normal"
},
"world_context": {
"active_projects": ["proj-1", "proj-2"],
"related_entities": ["entity-1", "entity-2", "entity-3"],
"open_loops": [],
"retrieved_at": "2025-12-09T17:00:00"
}
}
Backward Compatibility: - All Phase 2 services are optional - Falls back to Phase 1 behavior if services unavailable - Existing tests continue to pass
4. Backend Wiring (backend/core/lifecycle_manager.py)¶
Integration: - WorldModelService initialized with KG storage, semantic memory, and memory manager - PersonalityService initialized with database connection - Both services passed to AgencyEngine constructor - Graceful fallback with warnings if initialization fails
Startup Logs:
β
[AI_PROCESSORS] Created WorldModelService (Phase 2)
β
[AI_PROCESSORS] Created PersonalityService (Phase 2)
β
Created AgencyEngine with shared database connection
5. Testing (backend/tests/integration/agency/test_phase2_context_integration.py)¶
Test Coverage: - β Backward compatibility (goals without Phase 2 services) - β Graceful fallback when services unavailable - β PersonalityService basic functionality - β Priority adjustment based on traits - β Proactivity calculation - β AgencyEngine with PersonalityService - β Goal metadata enrichment - β Custom metadata preservation
Test Results:
All Phase 1 tests continue to pass, confirming backward compatibility.
π Phase 2 Roadmap Status¶
β AMS Integration (v1)¶
- Connect Goal System and Planning to AMS for retrieving context
- Use AMS summaries and open-loop lists (WIP: open loops are currently placeholder)
- Track AMS unified indexing (Phase 4+ optimization)
β World Model & Knowledge/Property Graph (v1)¶
- Implement WorldModelService API
- Provide basic queries (entities, projects, contexts)
- Expose world model views to Planner
β Social & Personality Hooks¶
- Wire Personality Simulation traits into goal creation
- Include relationship vectors in goal selection
- Proactivity adjustment per user
π― Phase 2 Exit Condition¶
"Goals and plans are meaningfully influenced by long-term memory, social context, and world structure; AICO feels more consistent and 'aware' over time."
Status: β ACHIEVED
- β Goals influenced by KG entities and projects
- β Priority adjusted by personality traits (conscientiousness)
- β Proactivity based on relationship vectors (closeness + preference)
- β³ AMS summaries (placeholder, full integration in Phase 4+)
π Implementation Notes¶
Key Design Decisions¶
- Optional Services: All Phase 2 services are optional to maintain backward compatibility
- Graceful Degradation: System falls back to Phase 1 behavior if services unavailable
- Lazy Initialization: Loggers initialized lazily to avoid import errors in tests
- Priority Levels: Only LOW, NORMAL, HIGH (no URGENT) to match existing enum
- Metadata Preservation: Custom metadata preserved alongside Phase 2 enrichment
Bug Fixes During Implementation¶
- Logger Import Errors: Fixed by lazy initialization in PersonalityService
- URGENT Priority: Removed non-existent URGENT level from priority maps
- PERSONALITY_AVAILABLE Flag: Removed checks, rely on service instance directly
- Metadata Serialization: Verified JSON serialization/deserialization works correctly
π Usage Examples¶
Basic Goal Creation (Phase 1 - Still Works)¶
engine = AgencyEngine(config, db_connection)
goal, plan = await engine.create_goal_with_optional_plan(
user_id=user_id,
title="Complete project documentation",
priority=GoalPriority.NORMAL,
auto_plan=True,
)
Goal Creation with World Context (Phase 2)¶
engine = AgencyEngine(config, db_connection, world_model=world_model)
goal, plan = await engine.create_goal_with_world_context(
user_id=user_id,
title="Complete project documentation",
priority=GoalPriority.NORMAL,
auto_plan=True,
)
# goal.metadata now includes 'world_context' with projects and entities
Goal Creation with Full Context (Phase 2 - Recommended)¶
engine = AgencyEngine(
config,
db_connection,
world_model=world_model,
personality_service=personality,
)
goal, plan = await engine.create_goal_with_full_context(
user_id=user_id,
title="Complete project documentation",
priority=GoalPriority.NORMAL, # May be adjusted based on personality
auto_plan=True,
)
# goal.metadata includes both 'personality_context' and 'world_context'
# goal.priority may be adjusted based on conscientiousness
π¦ Files Modified/Created¶
Created Files (9)¶
shared/aico/ai/world_model/__init__.pyshared/aico/ai/world_model/models.pyshared/aico/ai/world_model/service.pyshared/aico/ai/personality/__init__.pyshared/aico/ai/personality/models.pyshared/aico/ai/personality/service.pybackend/tests/integration/agency/test_phase2_context_integration.pydocs/concepts/agency/phase2-integration-design.mddocs/concepts/agency/phase2-implementation-summary.md(this file)
Modified Files (3)¶
shared/aico/ai/agency/engine.py- Added Phase 2 methods and parametersbackend/core/lifecycle_manager.py- Wired Phase 2 servicesdocs/concepts/agency/agency-roadmap.md- Updated completion status
β Next Steps¶
Phase 2 is complete and production-ready. Recommended next actions:
- Monitor in Production: Observe personality adjustments and world context usage
- Tune Personality Defaults: Adjust default AICO personality traits based on user feedback
- Phase 3 Planning: Begin Curiosity Engine and intrinsic motivation implementation
- AMS Summaries: Implement full open loops retrieval (currently placeholder)
- Documentation: Update API docs with Phase 2 methods
π Summary¶
Phase 2 successfully delivers: - β Context-aware goal creation - β Personality-based priority adjustment - β Relationship-driven proactivity - β World model integration - β Full backward compatibility - β Comprehensive test coverage
The Agency system is now meaningfully influenced by long-term memory, social context, and world structure, making AICO feel more consistent and "aware" over time.