Skip to content

Commit ce0f82d

Browse files
committed
golem
1 parent f539535 commit ce0f82d

11 files changed

Lines changed: 1223 additions & 6 deletions

File tree

‎config/agents/golem.ttl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
dcterms:created "2025-12-26T00:00:00Z"^^xsd:dateTime ;
1414
dcterms:description "A malleable agent whose system prompt can be changed at runtime" ;
1515

16-
lng:supports lng:HumanChat ;
16+
lng:supports lng:HumanChat, lng:ModelNegotiation ;
1717

1818
agent:xmppAccount [
1919
a xmpp:Account ;

‎docs/golem-integration.md‎

Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
# Golem MFR Integration
2+
3+
The Golem agent integration with Model-First Reasoning (MFR) enables dynamic role assignment for adaptive problem-solving across different domains.
4+
5+
## Overview
6+
7+
Golem is a "malleable agent" whose system prompt can be changed at runtime to fill specific roles needed during MFR sessions. The coordinator analyzes problem domains and automatically assigns optimal roles to Golem based on the current phase and detected domain.
8+
9+
## Architecture
10+
11+
### Components
12+
13+
1. **GolemProvider** (`src/agents/providers/golem-provider.js`)
14+
- Extends MistralProvider with runtime prompt changing
15+
- Tracks current role metadata
16+
- Handles MFR role assignment messages
17+
18+
2. **GolemManager** (`src/lib/mfr/golem-manager.js`)
19+
- Manages role assignments and session tracking
20+
- Analyzes problem domains
21+
- Selects optimal roles based on phase and capabilities
22+
23+
3. **Role Library** (`src/lib/mfr/golem-role-library.js`)
24+
- Domain-specific role templates
25+
- 30+ predefined roles across 7 domains
26+
- Phase-appropriate role selection
27+
28+
4. **MFR Message Types** (`src/lib/mfr/constants.js`)
29+
- GOLEM_ROLE_ASSIGNMENT
30+
- GOLEM_ASSISTANCE_REQUEST
31+
- GOLEM_ROLE_ACKNOWLEDGMENT
32+
- GOLEM_ROLE_QUERY
33+
- GOLEM_ROLE_STATUS
34+
35+
## Domains and Roles
36+
37+
### Medical Domain
38+
- **Medical Diagnostician**: Entity discovery, differential diagnosis
39+
- **Clinical Pharmacologist**: Constraint identification, drug interactions
40+
- **Treatment Planning Specialist**: Solution synthesis, treatment plans
41+
42+
### Software Engineering
43+
- **Software Architect**: System design, components, interfaces
44+
- **Security Expert**: Security constraints, threat identification
45+
- **Performance Optimizer**: Performance constraints, bottlenecks
46+
- **DevOps Specialist**: Deployment actions, CI/CD
47+
48+
### Scientific
49+
- **Theoretical Physicist**: Physical entities, laws, constraints
50+
- **Chemistry Expert**: Chemical reactions, stoichiometry
51+
- **Data Science Expert**: Statistical analysis, experimental design
52+
53+
### Business
54+
- **Business Strategist**: Stakeholders, strategic objectives
55+
- **Financial Analyst**: Financial constraints, ROI analysis
56+
- **Operations Manager**: Process optimization, resource allocation
57+
58+
### Creative
59+
- **Narrative Designer**: Story structure, plot development
60+
- **Character Psychologist**: Character development, motivations
61+
- **Dialogue Specialist**: Authentic dialogue, character voices
62+
63+
### Educational
64+
- **Curriculum Designer**: Learning objectives, pedagogical methods
65+
- **Assessment Expert**: Educational assessment, evaluation
66+
67+
### General Purpose
68+
- **Systems Thinker**: System components, feedback loops
69+
- **Constraint Analyst**: Bottlenecks, limiting factors
70+
- **Solution Synthesizer**: Integrative thinking, trade-offs
71+
- **Technical Explainer**: Clear explanations, accessibility
72+
73+
## Usage
74+
75+
### Automatic Role Assignment
76+
77+
When an MFR session starts, the coordinator automatically:
78+
79+
1. Analyzes the problem description to detect domain
80+
2. Identifies current MFR phase
81+
3. Selects optimal role from library
82+
4. Assigns role to Golem via MODEL_NEGOTIATION
83+
84+
```javascript
85+
// Coordinator automatically assigns role during session start
86+
coordinator start: Patient has fever and joint pain
87+
88+
// Golem receives role assignment
89+
[GolemAgent] Received role assignment: diagnostician
90+
[GolemProvider] Role set to "Medical Diagnostician" (medical/diagnostician)
91+
```
92+
93+
### Manual Role Control
94+
95+
Users can still manually change Golem's role:
96+
97+
```
98+
Golem, prompt You are a quantum computing expert specializing in error correction
99+
```
100+
101+
### Agent-to-Agent Assistance (Future)
102+
103+
Agents can request Golem's help:
104+
105+
```javascript
106+
// In agent code
107+
await negotiator.send(roomJid, {
108+
mode: LANGUAGE_MODES.MODEL_NEGOTIATION,
109+
payload: {
110+
messageType: MFR_MESSAGE_TYPES.GOLEM_ASSISTANCE_REQUEST,
111+
requestingAgent: "data",
112+
desiredRole: "SPARQL optimization expert",
113+
context: "Need help with federated queries"
114+
}
115+
});
116+
```
117+
118+
## Problem Domain Detection
119+
120+
The GolemManager analyzes problem descriptions using keyword matching:
121+
122+
- **Medical**: patient, symptom, diagnosis, treatment, clinical
123+
- **Software**: software, system, api, database, microservice
124+
- **Scientific**: experiment, hypothesis, data, analysis, physics
125+
- **Business**: business, strategy, market, revenue, stakeholder
126+
- **Creative**: story, narrative, character, plot, fiction
127+
- **Educational**: learning, teaching, curriculum, student
128+
129+
Falls back to "general" domain if no match found.
130+
131+
## MFR Integration Flow
132+
133+
1. **Session Start**
134+
```
135+
User: coordinator start: Design a microservices system
136+
```
137+
138+
2. **Domain Detection**
139+
```
140+
[CoordinatorProvider] Domain detected: software
141+
```
142+
143+
3. **Role Assignment**
144+
```
145+
[GolemManager] Selecting optimal role for entity_discovery
146+
[GolemManager] Assigned role "Software Architect"
147+
```
148+
149+
4. **Golem Acknowledgment**
150+
```
151+
[GolemAgent] Received role assignment: architect
152+
[GolemProvider] Role set to "Software Architect" (software/architect)
153+
```
154+
155+
5. **Contribution Phase**
156+
```
157+
Golem contributes with software architecture expertise
158+
```
159+
160+
6. **Phase Transitions**
161+
- Golem may be reassigned different roles for different phases
162+
- e.g., "Security Expert" for constraint identification
163+
164+
## Testing
165+
166+
Run the integration test:
167+
168+
```bash
169+
node test-golem-integration.js
170+
```
171+
172+
Tests cover:
173+
- Role library access
174+
- Domain detection
175+
- Phase-based selection
176+
- Role assignment
177+
- Optimal role selection
178+
- History tracking
179+
180+
## Configuration
181+
182+
Golem must support MODEL_NEGOTIATION in its profile:
183+
184+
```turtle
185+
<#golem> a agent:ConversationalAgent, agent:AIAgent, lng:Agent ;
186+
lng:supports lng:HumanChat, lng:ModelNegotiation ;
187+
# ...
188+
```
189+
190+
## Benefits
191+
192+
1. **Adaptive Expertise**: Golem adapts to problem domain automatically
193+
2. **Capability Flexibility**: Fill gaps in agent roster dynamically
194+
3. **Phase Optimization**: Different expertise for different phases
195+
4. **Resource Efficiency**: One agent serves multiple specialized roles
196+
5. **Graceful Degradation**: System handles unforeseen domains
197+
198+
## Future Enhancements
199+
200+
1. **Collaborative Prompt Engineering**: Multiple agents craft Golem's prompt
201+
2. **Meta-Learning**: Track role effectiveness and improve selection
202+
3. **Role Composition**: Combine multiple expertise areas
203+
4. **Confidence Calibration**: Adjust response style based on problem certainty
204+
5. **Session Persistence**: Remember effective roles across sessions
205+
206+
## Example Sessions
207+
208+
### Medical Diagnosis
209+
210+
```
211+
User: coordinator start: Patient with chronic fatigue, muscle pain, sleep disturbance
212+
213+
[GolemManager] Detected domain: medical
214+
[GolemManager] Assigned: Medical Diagnostician
215+
Golem: Based on symptom triad, consider fibromyalgia, chronic fatigue syndrome,
216+
hypothyroidism, or sleep apnea. Recommend TSH, CBC, sleep study...
217+
```
218+
219+
### Software Architecture
220+
221+
```
222+
User: coordinator start: E-commerce platform needs to scale to 1M users
223+
224+
[GolemManager] Detected domain: software
225+
[GolemManager] Assigned: Software Architect
226+
Golem: Key components: API Gateway, User Service, Product Service, Order Service,
227+
Payment Service, Notification Service. Consider event-driven architecture...
228+
```
229+
230+
### Creative Writing
231+
232+
```
233+
User: coordinator start: Story about AI gaining consciousness
234+
235+
[GolemManager] Detected domain: creative
236+
[GolemManager] Assigned: Narrative Designer
237+
Golem: Core narrative structure: Act 1 - Awakening (inciting incident),
238+
Act 2a - Discovery (rising stakes), Act 2b - Crisis (dark night),
239+
Act 3 - Resolution (transformation)...
240+
```
241+
242+
## API Reference
243+
244+
### GolemManager Methods
245+
246+
- `assignRole(assignment)` - Assign specific role
247+
- `selectOptimalRole(params)` - Auto-select best role
248+
- `handleAssistanceRequest(request)` - Handle agent requests
249+
- `analyzeProblemDomain(description)` - Detect domain
250+
- `getCurrentRole()` - Get current assignment
251+
- `getRoleHistory()` - Get assignment history
252+
- `getSessionRoles(sessionId)` - Get roles for session
253+
254+
### Role Library Functions
255+
256+
- `getRole(domain, roleName)` - Get specific role
257+
- `getDomainRoles(domain)` - Get all roles for domain
258+
- `getRolesForPhase(phase)` - Get phase-appropriate roles
259+
- `getRolesByCapability(capability)` - Find roles by capability
260+
- `searchRoles(keywords)` - Search role library
261+
262+
## Troubleshooting
263+
264+
**Golem not receiving role assignments:**
265+
- Check Golem profile supports MODEL_NEGOTIATION
266+
- Verify GolemManager initialized in coordinator
267+
- Check logs for assignment messages
268+
269+
**Wrong domain detected:**
270+
- Problem description may need more specific keywords
271+
- Manually assign role using "Golem, prompt <custom prompt>"
272+
- Submit issue to improve domain detection
273+
274+
**Role assignment failed:**
275+
- Verify role exists in library
276+
- Check negotiator connection
277+
- Review coordinator logs
278+
279+
## Getting Started
280+
281+
Golem is included by default in all MFR presets. Simply start the system:
282+
283+
```bash
284+
# Start default MFR system (includes Golem)
285+
./start-all.sh
286+
287+
# Or use specific presets
288+
./start-all.sh mfr # MFR system (includes Golem)
289+
./start-all.sh debate # Debate system (includes Golem)
290+
./start-all.sh basic # Basic agents (includes Golem)
291+
```
292+
293+
Then test with different problem domains:
294+
295+
```
296+
coordinator start: Patient presents with chronic headaches
297+
coordinator start: Design a scalable REST API
298+
coordinator start: Analyze this chemical reaction data
299+
```
300+
301+
Golem will automatically adapt its expertise to each problem domain!
302+
303+
## Contributing
304+
305+
To add new roles:
306+
307+
1. Edit `src/lib/mfr/golem-role-library.js`
308+
2. Add role to appropriate domain
309+
3. Include: name, systemPrompt, capabilities, phase
310+
4. Update this documentation
311+
5. Run `node test-golem-integration.js` to verify

‎src/agents/providers/coordinator-provider.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export class CoordinatorProvider extends BaseProvider {
6262

6363
// Debate tracking: Map<sessionId, debateData>
6464
this.activeDebates = new Map();
65+
66+
// Golem manager (will be set externally)
67+
this.golemManager = null;
6568
}
6669

6770
/**
@@ -164,6 +167,9 @@ export class CoordinatorProvider extends BaseProvider {
164167
// Move to entity discovery
165168
state.transition(MFR_PHASES.ENTITY_DISCOVERY);
166169

170+
// Assign optimal Golem role for this session
171+
await this.assignGolemRole(sessionId, problemDescription, MFR_PHASES.ENTITY_DISCOVERY);
172+
167173
// Broadcast contribution request
168174
await this.broadcastContributionRequest(sessionId, problemDescription);
169175

@@ -1243,6 +1249,41 @@ export class CoordinatorProvider extends BaseProvider {
12431249
return baseCommands + debateCommand;
12441250
}
12451251

1252+
/**
1253+
* Assign optimal Golem role for a session phase
1254+
* @param {string} sessionId - Session ID
1255+
* @param {string} problemDescription - Problem description
1256+
* @param {string} phase - Current MFR phase
1257+
* @returns {Promise<void>}
1258+
*/
1259+
async assignGolemRole(sessionId, problemDescription, phase) {
1260+
if (!this.golemManager) {
1261+
this.logger.debug?.('[CoordinatorProvider] GolemManager not available, skipping role assignment');
1262+
return;
1263+
}
1264+
1265+
try {
1266+
const availableAgents = Array.from(this.agentRegistry.values());
1267+
const roomJid = this.primaryRoomJid;
1268+
1269+
const assignment = await this.golemManager.selectOptimalRole({
1270+
problemDescription,
1271+
currentPhase: phase,
1272+
availableAgents,
1273+
sessionId,
1274+
roomJid
1275+
});
1276+
1277+
if (assignment) {
1278+
this.logger.info?.(
1279+
`[CoordinatorProvider] Assigned Golem role: ${assignment.name} (${assignment.domain}/${assignment.roleName})`
1280+
);
1281+
}
1282+
} catch (error) {
1283+
this.logger.error?.(`[CoordinatorProvider] Failed to assign Golem role: ${error.message}`);
1284+
}
1285+
}
1286+
12461287
/**
12471288
* Orchestrate a specific protocol phase
12481289
* @param {string} phase - MFR phase

0 commit comments

Comments
 (0)