Skip to content

Commit cf3349e

Browse files
haasonsaasclaude
andcommitted
feat: Add conversational AI-to-AI analysis tools
- Implement ConversationalGeminiService for multi-turn Claude-Gemini dialogues - Add ConversationManager for session state management - Add 4 new MCP tools: start_conversation, continue_conversation, finalize_conversation, get_conversation_status - Update DeepCodeReasonerV2 to support conversational analysis - Add examples demonstrating conversational analysis usage - Update README with conversational tools documentation and examples - Add uuid dependency for session ID generation This enables Claude and Gemini to engage in iterative problem-solving conversations for complex code analysis tasks that benefit from multi-turn refinement. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7a51582 commit cf3349e

12 files changed

Lines changed: 1536 additions & 1 deletion

README.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The "escalation" model treats LLMs like heterogeneous microservices - route to t
1717
## Features
1818

1919
- **Gemini 2.5 Pro Preview**: Uses Google's latest Gemini 2.5 Pro Preview (05-06) model with 1M token context window
20+
- **Conversational Analysis**: NEW! AI-to-AI dialogues between Claude and Gemini for iterative problem-solving
2021
- **Execution Flow Tracing**: Understands data flow and state transformations, not just function calls
2122
- **Cross-System Impact Analysis**: Models how changes propagate across service boundaries
2223
- **Performance Modeling**: Identifies N+1 patterns, memory leaks, and algorithmic bottlenecks
@@ -99,7 +100,63 @@ Add to your Claude Desktop configuration (`~/Library/Application Support/Claude/
99100

100101
**Note**: The tool parameters use snake_case naming convention and are validated using Zod schemas. The actual implementation provides more detailed type safety than shown in these simplified examples. Full TypeScript type definitions are available in `src/models/types.ts`.
101102

102-
### escalate_analysis
103+
### Conversational Analysis Tools
104+
105+
The server now includes AI-to-AI conversational tools that enable Claude and Gemini to engage in multi-turn dialogues for complex analysis:
106+
107+
#### start_conversation
108+
Initiates a conversational analysis session between Claude and Gemini.
109+
110+
```typescript
111+
{
112+
claude_context: {
113+
attempted_approaches: string[]; // What Claude tried
114+
partial_findings: any[]; // What Claude found
115+
stuck_description: string; // Where Claude got stuck
116+
code_scope: {
117+
files: string[]; // Files to analyze
118+
entry_points?: CodeLocation[]; // Starting points
119+
service_names?: string[]; // Services involved
120+
}
121+
};
122+
analysis_type: 'execution_trace' | 'cross_system' | 'performance' | 'hypothesis_test';
123+
initial_question?: string; // Optional opening question
124+
}
125+
```
126+
127+
#### continue_conversation
128+
Continues an active conversation with Claude's response or follow-up question.
129+
130+
```typescript
131+
{
132+
session_id: string; // Active session ID
133+
message: string; // Claude's message to Gemini
134+
include_code_snippets?: boolean; // Enrich with code context
135+
}
136+
```
137+
138+
#### finalize_conversation
139+
Completes the conversation and generates structured analysis results.
140+
141+
```typescript
142+
{
143+
session_id: string; // Active session ID
144+
summary_format: 'detailed' | 'concise' | 'actionable';
145+
}
146+
```
147+
148+
#### get_conversation_status
149+
Checks the status and progress of an ongoing conversation.
150+
151+
```typescript
152+
{
153+
session_id: string; // Session ID to check
154+
}
155+
```
156+
157+
### Traditional Analysis Tools
158+
159+
#### escalate_analysis
103160
Main tool for handing off complex analysis from Claude Code to Gemini.
104161

105162
```typescript
@@ -181,6 +238,37 @@ Test specific theories about code behavior.
181238

182239
## Example Use Cases
183240

241+
### Conversational Analysis Example
242+
243+
When Claude needs deep iterative analysis with Gemini:
244+
245+
```javascript
246+
// 1. Start conversation
247+
const session = await start_conversation({
248+
claude_context: {
249+
attempted_approaches: ["Checked for N+1 queries", "Profiled database calls"],
250+
partial_findings: [{ type: "performance", description: "Multiple DB queries in loop" }],
251+
stuck_description: "Can't determine if queries are optimizable",
252+
code_scope: { files: ["src/services/UserService.ts"] }
253+
},
254+
analysis_type: "performance",
255+
initial_question: "Are these queries necessary or can they be batched?"
256+
});
257+
258+
// 2. Continue with follow-ups
259+
const response = await continue_conversation({
260+
session_id: session.sessionId,
261+
message: "The queries fetch user preferences. Could we use a join instead?",
262+
include_code_snippets: true
263+
});
264+
265+
// 3. Finalize when ready
266+
const results = await finalize_conversation({
267+
session_id: session.sessionId,
268+
summary_format: "actionable"
269+
});
270+
```
271+
184272
### Case 1: Distributed Trace Analysis
185273

186274
When a failure signature spans multiple services with GB of logs:
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/**
2+
* Example of using the conversational MCP for AI-to-AI dialogue
3+
* between Claude and Gemini for deep code analysis
4+
*/
5+
6+
// Example 1: Performance Analysis Conversation
7+
async function performanceAnalysisExample() {
8+
// Claude starts the conversation
9+
const { sessionId, initialResponse, suggestedFollowUps } = await mcp.startConversation({
10+
claude_context: {
11+
attempted_approaches: [
12+
"Searched for N+1 query patterns",
13+
"Checked for obvious loops",
14+
"Analyzed database calls"
15+
],
16+
partial_findings: [
17+
{ type: "performance", description: "Found repeated DB calls in UserService" }
18+
],
19+
stuck_description: "Can't determine if the performance issue is from algorithm complexity or I/O bottlenecks",
20+
code_scope: {
21+
files: ["src/services/UserService.ts", "src/repositories/UserRepository.ts"],
22+
entry_points: ["getUserWithDetails"]
23+
}
24+
},
25+
analysis_type: "performance",
26+
initial_question: "I see repeated database calls but can't trace the full execution flow. Are these calls necessary or could they be optimized?"
27+
});
28+
29+
console.log("Gemini's initial analysis:", initialResponse);
30+
console.log("Suggested follow-ups:", suggestedFollowUps);
31+
32+
// Claude provides more context based on Gemini's questions
33+
const response1 = await mcp.continueConversation({
34+
session_id: sessionId,
35+
message: "The getUserWithDetails function is called in a loop from the API handler. Each user triggers 3-4 additional queries for related data. The data volume is typically 100-1000 users per request.",
36+
include_code_snippets: true
37+
});
38+
39+
// Gemini asks for specific runtime characteristics
40+
console.log("Gemini:", response1.response);
41+
// Expected: "That's a classic N+1 problem. Are these related queries for user roles, permissions, or preferences? Also, is there any caching layer between the service and database?"
42+
43+
// Claude provides runtime details
44+
const response2 = await mcp.continueConversation({
45+
session_id: sessionId,
46+
message: "The queries are for: user roles (1 query), permissions (1-2 queries), and preferences (1 query). No caching layer currently exists. The database is PostgreSQL with average query time of 10-15ms."
47+
});
48+
49+
// Gemini provides deeper analysis
50+
console.log("Gemini:", response2.response);
51+
console.log("Progress:", response2.analysisProgress);
52+
console.log("Can finalize:", response2.canFinalize);
53+
54+
// Finalize the conversation
55+
const finalAnalysis = await mcp.finalizeConversation({
56+
session_id: sessionId,
57+
summary_format: "actionable"
58+
});
59+
60+
console.log("Final recommendations:", finalAnalysis.recommendations);
61+
}
62+
63+
// Example 2: Complex Execution Trace with Back-and-Forth
64+
async function executionTraceExample() {
65+
// Claude initiates analysis of async execution flow
66+
const { sessionId, initialResponse } = await mcp.startConversation({
67+
claude_context: {
68+
attempted_approaches: [
69+
"Traced synchronous function calls",
70+
"Identified async/await patterns",
71+
"Looked for event emitters"
72+
],
73+
partial_findings: [
74+
{ type: "architecture", description: "Complex async flow with multiple event handlers" }
75+
],
76+
stuck_description: "Lost track of execution when events are emitted - can't determine order of operations",
77+
code_scope: {
78+
files: ["src/workers/DataProcessor.ts", "src/events/EventBus.ts"],
79+
entry_points: ["processDataBatch"]
80+
}
81+
},
82+
analysis_type: "execution_trace"
83+
});
84+
85+
// Conversational flow
86+
const conversation = [
87+
{
88+
claude: "I found event emitters for 'data.processed' and 'batch.complete' but can't trace their handlers",
89+
gemini: "I see the event handlers are registered dynamically. Are there any race conditions between these handlers?"
90+
},
91+
{
92+
claude: "Yes! Sometimes 'batch.complete' fires before all 'data.processed' events are handled. Here's the code where handlers are registered...",
93+
gemini: "This is a race condition. The batch completion check doesn't wait for pending promises. Let me trace the actual execution order..."
94+
}
95+
];
96+
97+
for (const turn of conversation) {
98+
const response = await mcp.continueConversation({
99+
session_id: sessionId,
100+
message: turn.claude,
101+
include_code_snippets: true
102+
});
103+
console.log("Gemini's response:", response.response);
104+
}
105+
106+
// Get final execution trace
107+
const finalAnalysis = await mcp.finalizeConversation({
108+
session_id: sessionId,
109+
summary_format: "detailed"
110+
});
111+
112+
console.log("Root causes found:", finalAnalysis.findings.rootCauses);
113+
}
114+
115+
// Example 3: Hypothesis Testing Through Dialogue
116+
async function hypothesisTestingExample() {
117+
const { sessionId } = await mcp.startConversation({
118+
claude_context: {
119+
attempted_approaches: ["Static analysis", "Pattern matching"],
120+
partial_findings: [
121+
{ type: "bug", description: "Intermittent null pointer exceptions in production" }
122+
],
123+
stuck_description: "Can't reproduce the issue locally - suspect it's related to concurrent access",
124+
code_scope: {
125+
files: ["src/cache/CacheManager.ts", "src/services/SessionService.ts"]
126+
}
127+
},
128+
analysis_type: "hypothesis_test",
129+
initial_question: "My hypothesis: the cache invalidation happens during read operations causing null returns. Can you help validate this?"
130+
});
131+
132+
// Multi-turn hypothesis refinement
133+
await mcp.continueConversation({
134+
session_id: sessionId,
135+
message: "The cache uses a simple Map without synchronization. Multiple services access it concurrently."
136+
});
137+
138+
const status = await mcp.getConversationStatus({ session_id: sessionId });
139+
console.log("Conversation status:", status);
140+
141+
// Continue until ready to finalize
142+
while (!status.canFinalize) {
143+
// Continue conversation based on Gemini's questions
144+
}
145+
146+
const result = await mcp.finalizeConversation({ session_id: sessionId });
147+
console.log("Validated hypotheses:", result.enrichedContext.validatedHypotheses);
148+
}
149+
150+
// Example 4: Cross-System Impact Analysis with Progressive Discovery
151+
async function crossSystemExample() {
152+
const { sessionId, initialResponse } = await mcp.startConversation({
153+
claude_context: {
154+
attempted_approaches: ["Checked API contracts", "Reviewed service dependencies"],
155+
partial_findings: [
156+
{ type: "architecture", description: "API change in UserService affects multiple consumers" }
157+
],
158+
stuck_description: "Can't trace all downstream impacts - some services use dynamic field access",
159+
code_scope: {
160+
files: ["src/api/UserAPI.ts"],
161+
service_names: ["UserService", "AuthService", "NotificationService"]
162+
}
163+
},
164+
analysis_type: "cross_system",
165+
initial_question: "Planning to change the user object structure. Which services will break?"
166+
});
167+
168+
// Progressive discovery through conversation
169+
console.log("Initial impact assessment:", initialResponse);
170+
171+
// Claude discovers new service dependencies during conversation
172+
await mcp.continueConversation({
173+
session_id: sessionId,
174+
message: "Just found that ReportingService also consumes user data through event streams. It expects the old field names."
175+
});
176+
177+
await mcp.continueConversation({
178+
session_id: sessionId,
179+
message: "The AnalyticsService has a batch job that processes user updates. It uses reflection to access fields dynamically."
180+
});
181+
182+
// Get comprehensive impact analysis
183+
const finalResult = await mcp.finalizeConversation({
184+
session_id: sessionId,
185+
summary_format: "detailed"
186+
});
187+
188+
console.log("All affected services:", finalResult.findings.crossSystemImpacts);
189+
console.log("Breaking changes:", finalResult.recommendations.immediateActions);
190+
}
191+
192+
export {
193+
performanceAnalysisExample,
194+
executionTraceExample,
195+
hypothesisTestingExample,
196+
crossSystemExample
197+
};

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"@google/generative-ai": "^0.24.1",
3636
"@modelcontextprotocol/sdk": "^0.5.0",
3737
"@types/node": "^20.0.0",
38+
"@types/uuid": "^10.0.0",
3839
"dotenv": "^16.3.1",
40+
"uuid": "^11.1.0",
3941
"zod": "^3.22.0"
4042
},
4143
"devDependencies": {

0 commit comments

Comments
 (0)