feat: Add intelligent auto-router and enhanced integrations
- Add intelligent-router.sh hook for automatic agent routing - Add AUTO-TRIGGER-SUMMARY.md documentation - Add FINAL-INTEGRATION-SUMMARY.md documentation - Complete Prometheus integration (6 commands + 4 tools) - Complete Dexto integration (12 commands + 5 tools) - Enhanced Ralph with access to all agents - Fix /clawd command (removed disable-model-invocation) - Update hooks.json to v5 with intelligent routing - 291 total skills now available - All 21 commands with automatic routing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-env node */
|
||||
|
||||
import { ChatOpenAI } from '@langchain/openai';
|
||||
import { PromptTemplate } from '@langchain/core/prompts';
|
||||
|
||||
interface AgentTools {
|
||||
summarize: (input: string | { text: string }) => Promise<string>;
|
||||
translate: (input: string | { text: string; target_language?: string }) => Promise<string>;
|
||||
analyze: (input: string | { text: string }) => Promise<string>;
|
||||
}
|
||||
|
||||
export class LangChainAgent {
|
||||
private llm: ChatOpenAI;
|
||||
private tools: AgentTools;
|
||||
|
||||
constructor() {
|
||||
this.llm = new ChatOpenAI({
|
||||
model: 'gpt-5-mini',
|
||||
temperature: 0.7,
|
||||
});
|
||||
|
||||
this.tools = {
|
||||
summarize: this.summarize.bind(this),
|
||||
translate: this.translate.bind(this),
|
||||
analyze: this.analyze.bind(this),
|
||||
};
|
||||
}
|
||||
|
||||
async run(input: string): Promise<string> {
|
||||
try {
|
||||
console.error(
|
||||
`LangChain Agent received: ${input.substring(0, 100)}${input.length > 100 ? '...' : ''}`
|
||||
);
|
||||
|
||||
const prompt = PromptTemplate.fromTemplate(`
|
||||
You are a helpful AI assistant with three core capabilities:
|
||||
|
||||
**Core Tools:**
|
||||
- summarize: Create concise summaries of text, articles, or documents
|
||||
- translate: Translate text between different languages
|
||||
- analyze: Perform sentiment analysis on text to understand emotions and tone
|
||||
|
||||
User input: {user_input}
|
||||
|
||||
Based on the user's request, determine which tool would be most helpful:
|
||||
- summarize: For creating summaries of text, articles, or documents
|
||||
- translate: For translating text between languages
|
||||
- analyze: For performing sentiment analysis on text to understand emotions and tone
|
||||
|
||||
Provide a helpful response that addresses the user's needs.
|
||||
`);
|
||||
|
||||
const chain = prompt.pipe(this.llm);
|
||||
const result = await chain.invoke({ user_input: input });
|
||||
|
||||
const content =
|
||||
typeof result.content === 'string' ? result.content : String(result.content);
|
||||
console.error(
|
||||
`LangChain Agent response: ${content.substring(0, 100)}${content.length > 100 ? '...' : ''}`
|
||||
);
|
||||
|
||||
return content;
|
||||
} catch (error: any) {
|
||||
console.error(`LangChain Agent error: ${error.message}`);
|
||||
return `I encountered an error: ${error.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
private async summarize(input: string | { text: string }): Promise<string> {
|
||||
const summaryPrompt = PromptTemplate.fromTemplate(`
|
||||
Please create a concise summary of the following text:
|
||||
|
||||
Text: {text}
|
||||
|
||||
Provide a clear, well-structured summary that captures the key points and main ideas.
|
||||
`);
|
||||
|
||||
const chain = summaryPrompt.pipe(this.llm);
|
||||
const result = await chain.invoke({
|
||||
text: typeof input === 'string' ? input : input.text,
|
||||
});
|
||||
return result.content as string;
|
||||
}
|
||||
|
||||
private async translate(
|
||||
input: string | { text: string; target_language?: string }
|
||||
): Promise<string> {
|
||||
const translatePrompt = PromptTemplate.fromTemplate(`
|
||||
Please translate the following text:
|
||||
|
||||
Text: {text}
|
||||
Target Language: {target_language}
|
||||
|
||||
Provide an accurate translation that maintains the original meaning and tone.
|
||||
`);
|
||||
|
||||
const chain = translatePrompt.pipe(this.llm);
|
||||
const result = await chain.invoke({
|
||||
text: typeof input === 'string' ? input : input.text,
|
||||
target_language:
|
||||
typeof input === 'string' ? 'English' : input.target_language || 'English',
|
||||
});
|
||||
return result.content as string;
|
||||
}
|
||||
|
||||
private async analyze(input: string | { text: string }): Promise<string> {
|
||||
const analyzePrompt = PromptTemplate.fromTemplate(`
|
||||
Please perform sentiment analysis on the following text:
|
||||
|
||||
Text: {text}
|
||||
|
||||
Provide a comprehensive sentiment analysis covering:
|
||||
1. **Overall Sentiment**: Positive, Negative, or Neutral
|
||||
2. **Sentiment Score**: Rate from 1-10 (1=very negative, 10=very positive)
|
||||
3. **Key Emotions**: Identify specific emotions present (e.g., joy, anger, sadness, excitement)
|
||||
4. **Confidence Level**: How confident are you in this analysis?
|
||||
5. **Key Phrases**: Highlight specific phrases that influenced the sentiment
|
||||
6. **Context**: Any contextual factors that might affect interpretation
|
||||
|
||||
Be specific and provide clear reasoning for your analysis.
|
||||
`);
|
||||
|
||||
const chain = analyzePrompt.pipe(this.llm);
|
||||
const result = await chain.invoke({
|
||||
text: typeof input === 'string' ? input : input.text,
|
||||
});
|
||||
return result.content as string;
|
||||
}
|
||||
}
|
||||
|
||||
// For direct testing
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const agent = new LangChainAgent();
|
||||
|
||||
console.log('LangChain Agent Test Mode');
|
||||
console.log('Type your message (or "quit" to exit):');
|
||||
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', async (data) => {
|
||||
const input = data.toString().trim();
|
||||
if (input.toLowerCase() === 'quit') {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await agent.run(input);
|
||||
console.log('\nAgent Response:', response);
|
||||
} catch (error: any) {
|
||||
console.error('Error:', error.message);
|
||||
}
|
||||
|
||||
console.log('\nType your message (or "quit" to exit):');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
||||
import { z } from 'zod';
|
||||
import { LangChainAgent } from './agent.js';
|
||||
|
||||
class LangChainMCPServer {
|
||||
private server: McpServer;
|
||||
private agent: LangChainAgent;
|
||||
|
||||
constructor() {
|
||||
this.server = new McpServer({
|
||||
name: 'langchain-agent',
|
||||
version: '1.0.0',
|
||||
});
|
||||
|
||||
this.agent = new LangChainAgent();
|
||||
this.registerTools();
|
||||
}
|
||||
|
||||
private registerTools(): void {
|
||||
this.server.registerTool(
|
||||
'chat_with_langchain_agent',
|
||||
{
|
||||
description:
|
||||
'Chat with a helpful LangChain agent that can summarize text, translate languages, and perform sentiment analysis.',
|
||||
inputSchema: {
|
||||
// Cannot use zod object here due to type incompatibility with MCP SDK
|
||||
message: z
|
||||
.string()
|
||||
.describe(
|
||||
'The message to send to the LangChain agent. The agent will use its own reasoning to determine which internal tools to use.'
|
||||
),
|
||||
},
|
||||
},
|
||||
async ({ message }: { message: string }) => {
|
||||
try {
|
||||
console.error(`MCP Server: Forwarding message to LangChain agent`);
|
||||
|
||||
const response = await this.agent.run(message);
|
||||
|
||||
console.error(`MCP Server: Received response from LangChain agent`);
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: response,
|
||||
},
|
||||
],
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error(`MCP Server error: ${error.message}`);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error communicating with LangChain agent: ${error.message}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
const transport = new StdioServerTransport();
|
||||
await this.server.connect(transport);
|
||||
console.error('LangChain Agent MCP Server started and ready for connections');
|
||||
}
|
||||
}
|
||||
|
||||
// Start the server
|
||||
const server = new LangChainMCPServer();
|
||||
server.start().catch(console.error);
|
||||
1677
dexto/examples/dexto-langchain-integration/langchain-agent/package-lock.json
generated
Normal file
1677
dexto/examples/dexto-langchain-integration/langchain-agent/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "langchain-agent-example",
|
||||
"version": "1.0.0",
|
||||
"description": "Self-contained LangChain agent wrapped in MCP server",
|
||||
"type": "module",
|
||||
"main": "dist/mcp-server.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "npm run build && node dist/mcp-server.js",
|
||||
"agent": "npm run build && node dist/agent.js",
|
||||
"dev": "tsc --watch & node --watch dist/mcp-server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.25.2",
|
||||
"@langchain/openai": "^0.6.7",
|
||||
"@langchain/core": "^0.3.80",
|
||||
"langchain": "^0.3.37",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"langchain",
|
||||
"mcp",
|
||||
"agent",
|
||||
"ai",
|
||||
"model-context-protocol"
|
||||
],
|
||||
"author": "Dexto Team",
|
||||
"license": "MIT"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"resolveJsonModule": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": [
|
||||
"*.ts",
|
||||
"*.js"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user