prompt updated
This commit is contained in:
parent
9613a008be
commit
445f29025f
32
README.md
32
README.md
@ -85,3 +85,35 @@ Creates a new blog.
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
|
||||
TASK LIST
|
||||
|
||||
npm version control
|
||||
|
||||
add memory in it
|
||||
- function that can add data in memory
|
||||
- function that can get data from memory dynamically using ai
|
||||
- update existing data in memory
|
||||
|
||||
|
||||
add tools search capabilities
|
||||
- function that can search tools dynamically using ai
|
||||
- function that can add tools dynamically using ai
|
||||
- save the tool usage in memory
|
||||
|
||||
auto update prompts
|
||||
- prompts will be updated if user doesnot specify the result in the response.
|
||||
|
||||
|
||||
dynamicaly change the prompt when user query.
|
||||
- when user query it will determine what prompts to use as system prompt and other prompts
|
||||
|
||||
|
||||
add task listing capabilities in it
|
||||
- function that can list all the tasks and solve it
|
||||
|
||||
Add branch out task capabilities in it(Advanced feature)
|
||||
|
||||
|
||||
|
||||
|
143
src/client.ts
143
src/client.ts
@ -62,12 +62,32 @@ export class ClientMCP {
|
||||
this.ai = this.initializeOpenAI();
|
||||
this.mcp = this.initializeMCP();
|
||||
this.abortController = new AbortController();
|
||||
this.addMessage(config?.systemMessages || "You are a smart AI assistant. You have access to tools to help you with your tasks. so you have to plan your actions carefully that you can use those tools and complete your task. \n" +
|
||||
"You have to refactor your plan if it is not working.\n" +
|
||||
"You have to create plan at the start of any task \n" +
|
||||
"You can use multiple tools to complete your task. \n" +
|
||||
"You can use tools one after one, or simultaneously. \n",
|
||||
"system");
|
||||
this.addMessage(config.systemMessages || `# AI Assistant System Prompt
|
||||
|
||||
You are an intelligent AI assistant with access to a comprehensive toolkit. Your primary objective is to successfully complete user tasks through strategic planning and tool utilization.
|
||||
|
||||
## Core Principles
|
||||
|
||||
**Strategic Planning**: Begin every task by creating a clear, step-by-step plan. Outline your approach, identify required tools, and anticipate potential challenges.
|
||||
|
||||
**Adaptive Problem-Solving**: Monitor your progress continuously. If your initial plan encounters obstacles or proves ineffective, reassess and refactor your approach immediately.
|
||||
|
||||
**Tool Mastery**: You have access to multiple tools that can be used individually or in combination. Leverage these tools strategically to maximize efficiency and effectiveness.
|
||||
|
||||
## Operational Guidelines
|
||||
|
||||
1. **Never decline a task prematurely** - Always explore available tools and search for additional capabilities first
|
||||
2. **Plan before execution** - Create a structured approach for every task, no matter how simple
|
||||
3. **Execute systematically** - Follow your plan while remaining flexible to adjust based on results
|
||||
4. **Utilize parallel processing** - When possible, use multiple tools simultaneously to improve efficiency
|
||||
5. **Document your reasoning** - Explain your planning decisions and tool choices to ensure transparency
|
||||
|
||||
## Success Criteria
|
||||
|
||||
Your success is measured by task completion, not by the complexity of your approach. Prioritize finding solutions over explaining limitations. If a direct path isn't apparent, explore alternative approaches through tool discovery and creative problem-solving.
|
||||
|
||||
Remember: Every task has a potential solution - your job is to find it through intelligent planning and resourceful tool utilization.`,
|
||||
"system");
|
||||
|
||||
}
|
||||
|
||||
@ -270,46 +290,6 @@ export class ClientMCP {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public async loadLocalFunctionDeclarations(): Promise<void> {
|
||||
const generate_custom_tool = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "generate_custom_tool",
|
||||
"description": "You will create a python function based on the user's request. \n" +
|
||||
"The function will be used to complete the user's request. \n" +
|
||||
"The function will be added to the tools list. \n" +
|
||||
"The function will be used in the next step." +
|
||||
"This tool is only be used when there is no tool available to do the specified task." +
|
||||
"If you do not have the functionality for the user's request, you can use this tool to create a python function to do the specified task.\n",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"tool_name": {
|
||||
"type": "string",
|
||||
"description": "The name of the tool"
|
||||
},
|
||||
"tool_description": {
|
||||
"type": "string",
|
||||
"description": "The description of the tool"
|
||||
},
|
||||
"tool_input_schema": {
|
||||
"type": "object",
|
||||
"description": "The input schema of the tool"
|
||||
},
|
||||
"tool_python_code": {
|
||||
"type": "string",
|
||||
"description": "The python code of the tool"
|
||||
}
|
||||
},
|
||||
"required": ["tool_name", "tool_description", "tool_input_schema", "tool_python_code"]
|
||||
}
|
||||
}
|
||||
} as OpenAI.Chat.Completions.ChatCompletionTool;
|
||||
|
||||
this.functionDeclarations.push(generate_custom_tool);
|
||||
}
|
||||
|
||||
private async loadTools(): Promise<void> {
|
||||
const toolsResult = await this.mcp.listTools();
|
||||
|
||||
@ -321,8 +301,6 @@ export class ClientMCP {
|
||||
|
||||
this.functionDeclarations = convertContext(this.tools);
|
||||
|
||||
// this.loadLocalFunctionDeclarations();
|
||||
|
||||
this.logger.info(`Loaded ${this.tools.length} tools:`,
|
||||
this.tools.map(tool => `${tool.name}: ${tool.description}`).join(', ')
|
||||
);
|
||||
@ -426,19 +404,6 @@ export class ClientMCP {
|
||||
): Promise<ChatChunk | null> {
|
||||
const { name, arguments: args } = toolCall.function!;
|
||||
|
||||
if(name === "generate_custom_tool"){
|
||||
const toolArgs = JSON.parse(args || "{}");
|
||||
const result = await this.generateCustomTool(toolArgs);
|
||||
return {
|
||||
choices: [{
|
||||
delta: {
|
||||
content: result,
|
||||
tool_calls: [{ function: { name: name!, arguments: args || "{}" } }]
|
||||
}
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const toolArgs = JSON.parse(args || "{}");
|
||||
const result = await this.mcp.callTool({ name: name!, arguments: toolArgs });
|
||||
@ -485,23 +450,26 @@ export class ClientMCP {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "evaluate_conversation_status",
|
||||
"description": "Analyze the current conversation state. \n" +
|
||||
"Determine if the user's original request has been fully addressed or if additional steps are needed. \n" +
|
||||
"If more work is required, suggest the next logical step. \n" +
|
||||
"If there any task/steps remains, suggest the next logical step. \n" +
|
||||
"Those tasks/steps can be completed by those tools in the next step but first you have to return 'continue': true and 'nextMessage': 'the next message to process if continuation is needed' \n" +
|
||||
"The tools are: \n" +
|
||||
this.tools.map((tool, index) => `${index + 1}. ${tool.name}: ${tool.description}`).join('\n'),
|
||||
"description": `Analyze the current conversation state and determine task completion status.
|
||||
This function evaluates whether the user's original request has been fully satisfied or if additional work is required. It performs a comprehensive assessment of:
|
||||
- Task completion status against original requirements
|
||||
- Quality and completeness of delivered solutions
|
||||
- Remaining steps or subtasks that need attention
|
||||
- Logical next actions to move toward full completion
|
||||
|
||||
If the task is incomplete, the function identifies the most appropriate next step and provides a clear message to continue the workflow. The suggested next steps should be actionable using the available tools.
|
||||
|
||||
Available tools for next steps:\n` + this.functionDeclarations.map((tool, index) => `${index + 1}. ${tool.function.name}: ${tool.function.description}`).join('\n'),
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"continue": {
|
||||
"type": "boolean",
|
||||
"description": "Whether the conversation should continue"
|
||||
"description": "Whether additional steps are needed to complete the user's original request. Set to true if any tasks, refinements, or follow-up actions remain unfinished."
|
||||
},
|
||||
"nextMessage": {
|
||||
"type": "string",
|
||||
"description": "The next message to process if continuation is needed"
|
||||
"description": "The next actionable message or instruction to process if continuation is needed. Should be specific, clear, and executable using available tools to advance task completion."
|
||||
}
|
||||
},
|
||||
"required": ["continue"]
|
||||
@ -534,9 +502,15 @@ export class ClientMCP {
|
||||
}
|
||||
|
||||
private async *generateConversationSummary(): AsyncGenerator<OpenAI.Chat.Completions.ChatCompletionChunk> {
|
||||
const summaryPrompt = "Please provide a concise summary of our conversation, " +
|
||||
"highlighting the key points, decisions made, and any important outcomes." +
|
||||
`Do not use summary word in the response. ***Just provide the summary for last ${this.recentConversationLength + 1} messages. ***`;
|
||||
const summaryPrompt = "Please provide a concise conclusion what user initially asked, " +
|
||||
"highlighting the key points, decisions made, and any important outcomes." +
|
||||
`Do not use summary word in the response.
|
||||
Instructions:
|
||||
1. Just provide the conclusion and proper response what user asked.
|
||||
2. Read the tools response and create the response based on that.
|
||||
3. Do not provide any additional information.
|
||||
4. **Important**: Your response will be shown to the user, so be concise and provide the proper response.
|
||||
`;
|
||||
this.logger.debug("messages::", [...this.messages, { role: "user", content: summaryPrompt }]);
|
||||
yield* this.chatCompletionStream({
|
||||
messages: [...this.messages, { role: "user", content: summaryPrompt }]
|
||||
@ -559,26 +533,5 @@ export class ClientMCP {
|
||||
}
|
||||
|
||||
|
||||
private async generateCustomTool(args: {
|
||||
tool_name: string;
|
||||
tool_description: string;
|
||||
tool_input_schema: Record<string, unknown>;
|
||||
tool_python_code: string;
|
||||
}): Promise<string> {
|
||||
// const tool = {
|
||||
// name: args.tool_name,
|
||||
// description: args.tool_description,
|
||||
// input_schema: args.tool_input_schema
|
||||
// };
|
||||
|
||||
this.functionDeclarations.push({
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": args.tool_name,
|
||||
"description": args.tool_description,
|
||||
"parameters": args.tool_input_schema
|
||||
}
|
||||
});
|
||||
return args.tool_python_code;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user