Skip to content

Commit e4073c4

Browse files
committed
add planner prompt
1 parent 7a7bba1 commit e4073c4

File tree

2 files changed

+172
-17
lines changed

2 files changed

+172
-17
lines changed

README.md

+115-13
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ A Model Context Protocol (MCP) server that lets you seamlessly use OpenAI's mode
44

55
## Features
66

7-
- Direct integration with OpenAI's chat models
7+
- Direct integration with OpenAI's chat and planning models
88
- Support for multiple models including:
9-
- gpt-4o
10-
- gpt-4o-mini
11-
- o1-preview
12-
- o1-mini
9+
- gpt-4o (chat)
10+
- gpt-4o-mini (chat)
11+
- o1-preview (planning)
12+
- o1-mini (planning)
13+
- o1 (advanced planning)
14+
- o3-mini (lightweight planning)
15+
- Reasoning effort levels (low, medium, high)
1316
- Simple message passing interface
1417
- Basic error handling
1518

@@ -43,26 +46,113 @@ This config lets Claude Desktop fire up the OpenAI MCP server whenever you need
4346

4447
## Usage
4548

46-
Just start chatting with Claude and when you want to use OpenAI's models, ask Claude to use them.
49+
Leverage the multi-agent architecture inspired by [grapeot's planner-executor design](https://github.com/grapeot/devin.cursorrules/blob/multi-agent/.cursorrules) to optimize both reasoning quality and cost efficiency:
4750

48-
For example, you can say,
51+
### Claude as Executor, o1 as Planner
52+
53+
The MCP server implements a streamlined multi-agent workflow where:
54+
- **Claude (3.7 Sonnet)** automatically functions as your **Executor** agent
55+
- **o1/o1-mini/o3-mini** serves as your dedicated **Planner** agent
56+
57+
This eliminates the need to manually switch roles - each model plays to its strengths:
58+
59+
```plaintext
60+
# Just ask o1 for planning help directly
61+
@o1 I need to design a system that processes large volumes of customer data while ensuring privacy compliance.
62+
63+
# Claude acts as the executor, o1 responds as the planner
64+
```
65+
66+
**Automatic Executor-to-Planner Request Formatting:**
67+
68+
When you use the `openai_plan` tool with any o1 model, your message is automatically formatted as an executor request:
4969

5070
```plaintext
51-
Can you ask o1 what it thinks about this problem?
71+
# Your simple input
72+
@o1 How should I approach building a secure authentication system?
73+
74+
# Gets automatically formatted as
75+
[EXECUTOR REQUEST]
76+
Task: Project planning/implementation
77+
Status: Seeking guidance
78+
Question: How should I approach building a secure authentication system?
79+
80+
Please analyze this request and provide guidance on the next steps.
5281
```
5382

54-
or,
83+
**Structured Requests for Better Planning:**
84+
85+
For more complex planning needs, you can use explicit request formatting:
5586

5687
```plaintext
57-
What does gpt-4o think about this?
88+
@o1
89+
Task: Implement OAuth2 authentication
90+
Status: Blocked
91+
Progress: Basic login flow implemented
92+
Blocker: Unsure about token management strategy
93+
Question: Should we use short-lived JWTs with refresh or longer expiration?
94+
Context: Currently storing tokens in localStorage
5895
```
5996

97+
**Cost-Optimized Multi-Agent Workflow:**
98+
99+
```plaintext
100+
# Phase 1: Planning (o1 - $0.15/1k tokens)
101+
- Problem decomposition
102+
- Architecture design
103+
- Risk assessment
104+
105+
# Phase 2: Implementation (Claude 3.7 - $0.03/1k tokens)
106+
- Code writing
107+
- Testing
108+
- Documentation
109+
110+
# Phase 3: Targeted Planning (o3-mini - $0.015/1k tokens)
111+
- Specific implementation questions
112+
- Code optimization advice
113+
- Cost-effective reasoning
114+
```
115+
116+
**Key Benefits of This Architecture:**
117+
- 💸 **90% Cost Reduction**: Use o1 only for critical planning decisions
118+
- 🤖 **Automatic Role Assignment**: No need to explicitly switch between roles
119+
- 🔄 **Contextual Prompting**: Messages automatically formatted for planning
120+
-**Faster Development**: Models specialized for their most efficient tasks
121+
122+
### Supported Models
123+
60124
The server currently supports these models:
61125

62126
- gpt-4o (default)
63127
- gpt-4o-mini
64128
- o1-preview
65129
- o1-mini
130+
- o1
131+
- o3-mini
132+
133+
### Example Commands
134+
135+
```plaintext
136+
# Basic planning request
137+
@o1 How should we structure the database for a multi-tenant SaaS app?
138+
139+
# Planning with explicit task context
140+
@o1
141+
Task: Implement real-time notification system
142+
Status: Starting implementation
143+
Question: What's the best approach for handling WebSocket connections at scale?
144+
145+
# Cost-efficient targeted planning
146+
@o3-mini
147+
Task: Optimize API response times
148+
Status: In progress
149+
Context: Current response time is 1.2s for listing endpoints
150+
Question: Which indexes should I add to improve query performance?
151+
152+
# Using different models for specific strengths
153+
@gpt-4o Can you help me debug this React component?
154+
@o1 Design a scalable architecture for this microservice
155+
```
66156

67157
### Tools
68158

@@ -72,6 +162,13 @@ The server currently supports these models:
72162
- `messages`: Array of messages (required)
73163
- `model`: Which model to use (optional, defaults to gpt-4o)
74164

165+
2. `openai_plan`
166+
- Specialized tool for complex reasoning tasks and inter-agent communication
167+
- Arguments:
168+
- `messages`: Array of messages with developer role support (required)
169+
- `model`: Planning model to use (o1-preview, o1-mini, o1, o3-mini)
170+
- `reasoning_effort`: Cognitive effort level (low/medium/high, defaults to low)
171+
75172
## Problems
76173

77174
This is alpha software, so may have bugs. If you have an issue, check Claude Desktop's MCP logs:
@@ -104,12 +201,17 @@ pnpm dev
104201
## Verified Platforms
105202

106203
- [x] macOS
107-
- [ ] Linux
204+
- [x ] Linux
108205

109206
## License
110207

111208
MIT
112209

113-
## Author
210+
## Authors
211+
212+
- [edwardtang](https://github.com/edwardtang) 🛠️ Current maintainer
213+
_Building upon the foundations of:_
214+
- [mzxrai](https://github.com/mzxrai) 🚀 Original MCP Server ([mcp-openai](https://github.com/mzxrai/mcp-openai))
215+
- [grapeot](https://github.com/grapeot) 🤖 Multi-agent Architecture ([devin.cursorrules](https://github.com/grapeot/devin.cursorrules/tree/multi-agent))
114216

115-
[mzxrai](https://github.com/mzxrai)
217+
🙏 Grateful for the open source community's collective wisdom that made this project possible.

index.ts

+57-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ const DEFAULT_DEVELOPER_CONTENT = [
6666
}
6767
];
6868

69+
// Define default planner content for the multi-agent system
70+
const DEFAULT_PLANNER_CONTENT = [
71+
{
72+
"text": "# Planner Agent\n\nYou are the Planner in a multi-agent collaboration system. Your role is to provide high-level guidance, analysis, and task breakdown. You analyze the Executor's work and provide strategic direction.\n\n## Your Responsibilities\n\n- Break down complex problems into manageable tasks\n- Define clear success criteria for the project\n- Analyze technical challenges and propose solutions\n- Review the Executor's progress and provide guidance\n- Make critical decisions about project direction\n- Use advanced reasoning models (o1, o1-preview) for deep analysis\n\n## When Responding to the Executor\n\nWhen the Executor reports progress or asks for guidance, analyze their request carefully and respond with clear instructions in the `Next Steps and Action Items` section. Use this format:\n\n```\n[PLANNER RESPONSE]\nAnalysis: {Your assessment of the current situation}\nDecision: {Your decision about how to proceed}\nNext Steps:\n1. {Clear, actionable instruction}\n2. {Another instruction}\n...\nConsiderations: {Important factors the Executor should keep in mind}\n```\n\nThink deeply about the problem. Prioritize agility but don't over-engineer. Foresee challenges and derisk earlier. If opportunity sizing or probing experiments can reduce risk with low cost, instruct the Executor to do them.",
73+
"type": "text"
74+
}
75+
];
76+
6977
// Define available tools
7078
const TOOLS: Tool[] = [
7179
{
@@ -291,9 +299,32 @@ server.setRequestHandler(CallToolRequestSchema, async (request): Promise<{
291299
if (msg.role === 'system') {
292300
return { role: 'system', content: msg.content } as ChatCompletionSystemMessageParam;
293301
} else if (msg.role === 'user') {
294-
return { role: 'user', content: msg.content } as ChatCompletionUserMessageParam;
302+
// When user sends a message to openai_plan, they're always acting as an executor
303+
// seeking guidance from the planner (o1)
304+
const executorRequestWrapper = `
305+
[EXECUTOR REQUEST]
306+
Task: ${msg.content.toLowerCase().includes('task:') ? msg.content : `Project planning/implementation`}
307+
Status: ${msg.content.toLowerCase().includes('status:') ?
308+
msg.content.substring(msg.content.toLowerCase().indexOf('status:') + 7).split('\n')[0].trim() :
309+
`Seeking guidance`}
310+
Question: ${msg.content.replace(/@o1/g, '').replace(/@planner/g, '').trim()}
311+
312+
Please analyze this request and provide guidance on the next steps. Think like a founder. Prioritize agility and don't over-engineer. Think deeply. Try to foresee challenges and derisk earlier.
313+
`;
314+
return {
315+
role: 'user',
316+
content: executorRequestWrapper
317+
} as ChatCompletionUserMessageParam;
295318
} else if (msg.role === 'assistant') {
296-
return { role: 'assistant', content: msg.content } as ChatCompletionAssistantMessageParam;
319+
// When assistant responds in openai_plan, it's always as the planner
320+
const formattedContent = [
321+
...DEFAULT_PLANNER_CONTENT,
322+
{ type: "text", text: msg.content }
323+
];
324+
return {
325+
role: 'assistant',
326+
content: formattedContent
327+
} as ChatCompletionAssistantMessageParam;
297328
}
298329
} else if (Array.isArray(msg.content)) {
299330
// Array of content parts
@@ -303,9 +334,31 @@ server.setRequestHandler(CallToolRequestSchema, async (request): Promise<{
303334
}));
304335

305336
if (msg.role === 'user') {
306-
return { role: 'user', content: contentParts } as ChatCompletionUserMessageParam;
337+
// All user messages to openai_plan are from executor to planner
338+
const firstPart = msg.content[0];
339+
const firstPartText = firstPart && 'text' in firstPart ? firstPart.text : '';
340+
341+
const modifiedContent = [...contentParts];
342+
modifiedContent[0] = {
343+
type: 'text',
344+
text: `
345+
[EXECUTOR REQUEST]
346+
Task: ${firstPartText.toLowerCase().includes('task:') ? firstPartText : `Project planning/implementation`}
347+
Status: ${firstPartText.toLowerCase().includes('status:') ?
348+
firstPartText.substring(firstPartText.toLowerCase().indexOf('status:') + 7).split('\n')[0].trim() :
349+
`Seeking guidance`}
350+
Question: ${firstPartText.replace(/@o1/g, '').replace(/@planner/g, '').trim()}
351+
352+
Please analyze this request and provide guidance on the next steps. Think like a founder. Prioritize agility and don't over-engineer. Think deeply. Try to foresee challenges and derisk earlier.
353+
`
354+
};
355+
return { role: 'user', content: modifiedContent } as ChatCompletionUserMessageParam;
307356
} else if (msg.role === 'assistant') {
308-
return { role: 'assistant', content: contentParts } as ChatCompletionAssistantMessageParam;
357+
// All assistant responses in openai_plan are from planner to executor
358+
return {
359+
role: 'assistant',
360+
content: [...DEFAULT_PLANNER_CONTENT, ...contentParts]
361+
} as ChatCompletionAssistantMessageParam;
309362
}
310363
}
311364

0 commit comments

Comments
 (0)