Initial commit
This commit is contained in:
7
skills/ai-sdk-agents/assets/README.md
Normal file
7
skills/ai-sdk-agents/assets/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Assets
|
||||
|
||||
Bundled resources for ai-sdk-agents skill
|
||||
|
||||
- [ ] agent_template.ts: Template for creating new agents with pre-defined structure and interfaces.
|
||||
- [ ] example_coordinator.ts: Example implementation of a coordinator agent with routing logic.
|
||||
- [ ] example_workflow.json: Example workflow definition for a multi-agent system.
|
||||
110
skills/ai-sdk-agents/assets/agent_template.ts
Normal file
110
skills/ai-sdk-agents/assets/agent_template.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Agent Template
|
||||
*
|
||||
* This file provides a template for creating new agents within the ai-sdk-agents plugin.
|
||||
* Use this as a starting point to define the behavior and capabilities of your agent.
|
||||
*
|
||||
* Instructions:
|
||||
* 1. Replace the placeholder values with your agent's specific details.
|
||||
* 2. Implement the `execute` method to define the agent's core logic.
|
||||
* 3. Define the agent's tools and capabilities using the `AgentCapabilities` interface.
|
||||
* 4. Ensure your agent properly handles errors and exceptions.
|
||||
* 5. Consider adding logging and monitoring for improved observability.
|
||||
*/
|
||||
|
||||
import { Agent, AgentCapabilities, AgentContext } from '@ai-sdk/core'; // Replace with actual import path if needed
|
||||
|
||||
// Define the specific capabilities of this agent. Adjust as needed.
|
||||
interface MyAgentCapabilities extends AgentCapabilities {
|
||||
[key: string]: any; // Allows for flexible capability definitions. Consider more specific types.
|
||||
// Example:
|
||||
// summarizeText: (text: string) => Promise<string>;
|
||||
// translateText: (text: string, targetLanguage: string) => Promise<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* MyAgent Class
|
||||
*
|
||||
* A template for creating new AI agents.
|
||||
*/
|
||||
export class MyAgent implements Agent<MyAgentCapabilities> {
|
||||
// Agent Name (Required)
|
||||
name: string = "MyAgentName";
|
||||
|
||||
// Agent Description (Required)
|
||||
description: string = "A brief description of what this agent does.";
|
||||
|
||||
// (Optional) Specific instructions or persona for the agent
|
||||
instructions?: string = "You are a helpful assistant...";
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param capabilities - The capabilities of the agent (tools, functions, etc.).
|
||||
*/
|
||||
constructor(public capabilities: MyAgentCapabilities) {
|
||||
// Initialization logic can go here.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute Method
|
||||
*
|
||||
* This is the core logic of the agent. It receives the user's input and the agent's context.
|
||||
*
|
||||
* @param input - The user's input.
|
||||
* @param context - The agent's context (access to other agents, data, etc.).
|
||||
* @returns A promise that resolves to the agent's response.
|
||||
*/
|
||||
async execute(input: string, context: AgentContext): Promise<string> {
|
||||
try {
|
||||
// Implement your agent's logic here.
|
||||
// Example:
|
||||
// const summary = await this.capabilities.summarizeText(input);
|
||||
// return summary;
|
||||
|
||||
// Placeholder response:
|
||||
return `Agent ${this.name} received input: ${input}. This is a placeholder response.`;
|
||||
|
||||
} catch (error: any) {
|
||||
console.error(`Error in agent ${this.name}:`, error);
|
||||
return `Agent ${this.name} encountered an error: ${error.message || error}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Example Usage (for testing/demonstration purposes)
|
||||
*/
|
||||
async function main() {
|
||||
// Example capabilities (replace with actual implementations)
|
||||
const myCapabilities: MyAgentCapabilities = {
|
||||
// Example:
|
||||
// summarizeText: async (text: string) => `Summarized: ${text.substring(0, 50)}...`,
|
||||
// translateText: async (text: string, targetLanguage: string) => `Translated to ${targetLanguage}: ${text}`,
|
||||
};
|
||||
|
||||
const myAgent = new MyAgent(myCapabilities);
|
||||
|
||||
const context: AgentContext = {
|
||||
getAgent: async (name: string) => {
|
||||
console.warn(`Attempted to get agent ${name}, but no other agents are defined in this example.`);
|
||||
return undefined;
|
||||
},
|
||||
getPluginData: async (key: string) => {
|
||||
console.warn(`Attempted to get plugin data for key ${key}, but no plugin data is defined in this example.`);
|
||||
return undefined;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
const userInput = "This is a test input for the agent.";
|
||||
const response = await myAgent.execute(userInput, context);
|
||||
|
||||
console.log("Agent Response:", response);
|
||||
}
|
||||
|
||||
// Run the example (optional - remove in production)
|
||||
// main();
|
||||
100
skills/ai-sdk-agents/assets/example_coordinator.ts
Normal file
100
skills/ai-sdk-agents/assets/example_coordinator.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
// example_coordinator.ts
|
||||
|
||||
/**
|
||||
* This file provides an example implementation of a coordinator agent using the AI SDK.
|
||||
* Coordinator agents are responsible for routing requests to specialized agents and
|
||||
* managing the overall workflow of a multi-agent system.
|
||||
*
|
||||
* This example demonstrates basic routing logic. You can customize this to fit your specific use case.
|
||||
*/
|
||||
|
||||
import { Agent, AgentContext, AgentOutput, AgentConfig } from "@ai-sdk/core"; // Replace with actual import path if needed
|
||||
|
||||
// Define the interface for the agent's input. Customize this based on what your agents need.
|
||||
interface CoordinatorInput {
|
||||
query: string;
|
||||
// Add other relevant input parameters here
|
||||
}
|
||||
|
||||
// Define the interface for the agent's output. Customize this based on your needs.
|
||||
interface CoordinatorOutput extends AgentOutput {
|
||||
response: string;
|
||||
routedToAgent?: string; // Optional: Indicate which agent handled the request
|
||||
}
|
||||
|
||||
// Define the configuration options for the coordinator agent.
|
||||
interface CoordinatorConfig extends AgentConfig {
|
||||
// Add any configuration options specific to the coordinator agent here, such as:
|
||||
// - List of available agents and their descriptions
|
||||
// - Routing rules
|
||||
// - Error handling strategies
|
||||
agent1: Agent; // Define agent1
|
||||
agent2: Agent; // Define agent2
|
||||
}
|
||||
|
||||
// Implement the coordinator agent class.
|
||||
class CoordinatorAgent implements Agent<CoordinatorInput, CoordinatorOutput, CoordinatorConfig> {
|
||||
config: CoordinatorConfig;
|
||||
|
||||
constructor(config: CoordinatorConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async execute(input: CoordinatorInput, context: AgentContext): Promise<CoordinatorOutput> {
|
||||
const { query } = input;
|
||||
|
||||
// Implement your routing logic here. This is a simplified example.
|
||||
// Consider using more sophisticated methods like:
|
||||
// - Natural language understanding to determine the intent of the query
|
||||
// - A knowledge base to match the query to the appropriate agent
|
||||
// - A machine learning model to predict the best agent to handle the request
|
||||
|
||||
let routedToAgent: Agent | null = null;
|
||||
let agentName: string | undefined = undefined;
|
||||
|
||||
if (query.toLowerCase().includes("agent1")) {
|
||||
routedToAgent = this.config.agent1;
|
||||
agentName = "Agent1";
|
||||
} else if (query.toLowerCase().includes("agent2")) {
|
||||
routedToAgent = this.config.agent2;
|
||||
agentName = "Agent2";
|
||||
} else {
|
||||
// Default routing logic - you should customize this
|
||||
routedToAgent = this.config.agent1; // Example: Default to agent1
|
||||
agentName = "Agent1";
|
||||
}
|
||||
|
||||
|
||||
if (!routedToAgent) {
|
||||
return {
|
||||
response: "Error: No suitable agent found to handle the request.",
|
||||
};
|
||||
}
|
||||
|
||||
// Execute the selected agent.
|
||||
const agentOutput: any = await routedToAgent.execute({ query: query }, context); // Replace 'any' with the actual expected output type from the agent.
|
||||
|
||||
// Process the output from the selected agent and format it as the coordinator's output.
|
||||
return {
|
||||
response: `[${agentName ?? "Unknown Agent"}] ${agentOutput.response}`, // Customize formatting as needed
|
||||
routedToAgent: agentName,
|
||||
// Include any other relevant information in the output
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { CoordinatorAgent, CoordinatorInput, CoordinatorOutput, CoordinatorConfig };
|
||||
|
||||
// Example Usage (in another file):
|
||||
// import { CoordinatorAgent, CoordinatorConfig } from './example_coordinator';
|
||||
// import { Agent1, Agent2 } from './your_agents'; // Assuming you have Agent1 and Agent2 defined
|
||||
|
||||
// const config: CoordinatorConfig = {
|
||||
// agent1: new Agent1(),
|
||||
// agent2: new Agent2(),
|
||||
// // ... other configuration options
|
||||
// };
|
||||
|
||||
// const coordinator = new CoordinatorAgent(config);
|
||||
// const result = await coordinator.execute({ query: "Route this to agent1" }, context);
|
||||
// console.log(result.response);
|
||||
143
skills/ai-sdk-agents/assets/example_workflow.json
Normal file
143
skills/ai-sdk-agents/assets/example_workflow.json
Normal file
@@ -0,0 +1,143 @@
|
||||
{
|
||||
"_comment": "Example workflow definition for a multi-agent system powered by AI SDK v5.",
|
||||
"workflow_name": "Customer Service and Issue Resolution",
|
||||
"description": "A workflow that handles customer inquiries, escalates issues to specialists, and provides final resolutions.",
|
||||
"agents": [
|
||||
{
|
||||
"agent_id": "customer_service_agent",
|
||||
"name": "Customer Service Agent",
|
||||
"description": "First point of contact for all customer inquiries. Triages requests and routes them to appropriate specialists.",
|
||||
"model_provider": "anthropic",
|
||||
"model_name": "claude-3-opus-20240229",
|
||||
"prompt": "You are a friendly and helpful customer service agent. Your primary task is to understand the customer's issue and route it to the correct specialist. If you can resolve the issue directly, do so. Otherwise, summarize the problem clearly and pass it on. Be polite and professional at all times. If the customer is angry, use calming language.",
|
||||
"initial_state": true,
|
||||
"routing_rules": [
|
||||
{
|
||||
"condition": "The customer's issue is related to billing or payment.",
|
||||
"next_agent": "billing_specialist",
|
||||
"action": "Summarize the billing issue and forward it to the Billing Specialist."
|
||||
},
|
||||
{
|
||||
"condition": "The customer's issue is technical and requires expert assistance.",
|
||||
"next_agent": "technical_support_agent",
|
||||
"action": "Summarize the technical issue and forward it to the Technical Support Agent."
|
||||
},
|
||||
{
|
||||
"condition": "The customer is requesting information about products or services.",
|
||||
"next_agent": "sales_agent",
|
||||
"action": "Forward the inquiry to the Sales Agent."
|
||||
},
|
||||
{
|
||||
"condition": "The customer's issue can be resolved with readily available information.",
|
||||
"next_agent": null,
|
||||
"action": "Answer the customer's question directly and end the interaction."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"agent_id": "billing_specialist",
|
||||
"name": "Billing Specialist",
|
||||
"description": "Handles all billing and payment-related inquiries. Resolves billing disputes and provides payment options.",
|
||||
"model_provider": "openai",
|
||||
"model_name": "gpt-4-turbo-preview",
|
||||
"prompt": "You are a billing specialist. Your primary task is to resolve billing issues for customers. Clearly explain billing policies and provide payment options. If you cannot resolve the issue, escalate to a billing manager.",
|
||||
"routing_rules": [
|
||||
{
|
||||
"condition": "The billing issue is complex and requires managerial approval.",
|
||||
"next_agent": "billing_manager",
|
||||
"action": "Summarize the issue and forward it to the Billing Manager."
|
||||
},
|
||||
{
|
||||
"condition": "The billing issue can be resolved.",
|
||||
"next_agent": null,
|
||||
"action": "Resolve the billing issue and notify the customer."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"agent_id": "technical_support_agent",
|
||||
"name": "Technical Support Agent",
|
||||
"description": "Provides technical assistance to customers. Diagnoses and resolves technical issues.",
|
||||
"model_provider": "google",
|
||||
"model_name": "gemini-1.5-pro",
|
||||
"prompt": "You are a technical support agent. Your primary task is to diagnose and resolve technical issues reported by customers. Provide clear and concise instructions. If the issue requires a software update, guide the customer through the process.",
|
||||
"routing_rules": [
|
||||
{
|
||||
"condition": "The technical issue requires a software update.",
|
||||
"next_agent": null,
|
||||
"action": "Guide the customer through the software update process and verify the resolution."
|
||||
},
|
||||
{
|
||||
"condition": "The technical issue is beyond your expertise.",
|
||||
"next_agent": "escalation_team",
|
||||
"action": "Escalate the issue to the escalation team with a detailed description."
|
||||
},
|
||||
{
|
||||
"condition": "The technical issue is resolved.",
|
||||
"next_agent": null,
|
||||
"action": "Confirm the resolution with the customer and close the ticket."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"agent_id": "sales_agent",
|
||||
"name": "Sales Agent",
|
||||
"description": "Provides information about products and services and assists with sales inquiries.",
|
||||
"model_provider": "anthropic",
|
||||
"model_name": "claude-3-opus-20240229",
|
||||
"prompt": "You are a sales agent. Your primary task is to answer questions about our products and services and assist customers with their sales inquiries. Highlight key features and benefits. Offer promotions where available.",
|
||||
"routing_rules": [
|
||||
{
|
||||
"condition": "The customer is ready to make a purchase.",
|
||||
"next_agent": null,
|
||||
"action": "Guide the customer through the purchase process."
|
||||
},
|
||||
{
|
||||
"condition": "The customer has specific product questions.",
|
||||
"next_agent": null,
|
||||
"action": "Answer the customer's questions and provide relevant information."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"agent_id": "billing_manager",
|
||||
"name": "Billing Manager",
|
||||
"description": "Handles escalated billing issues that require managerial approval.",
|
||||
"model_provider": "openai",
|
||||
"model_name": "gpt-4-turbo-preview",
|
||||
"prompt": "You are a billing manager. Your primary task is to review and resolve escalated billing issues. Make decisions on exceptions and adjustments. Ensure compliance with billing policies.",
|
||||
"routing_rules": [
|
||||
{
|
||||
"condition": "The issue requires further investigation.",
|
||||
"next_agent": null,
|
||||
"action": "Investigate the issue and make a final decision."
|
||||
},
|
||||
{
|
||||
"condition": "The issue can be resolved with an exception.",
|
||||
"next_agent": null,
|
||||
"action": "Approve the exception and resolve the billing issue."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"agent_id": "escalation_team",
|
||||
"name": "Escalation Team",
|
||||
"description": "Handles complex technical issues that require specialized expertise.",
|
||||
"model_provider": "google",
|
||||
"model_name": "gemini-1.5-pro",
|
||||
"prompt": "You are part of the escalation team. Your primary task is to resolve complex technical issues that have been escalated. Collaborate with other experts and conduct thorough investigations.",
|
||||
"routing_rules": [
|
||||
{
|
||||
"condition": "The issue requires a code fix.",
|
||||
"next_agent": null,
|
||||
"action": "Develop and deploy a code fix to resolve the issue."
|
||||
},
|
||||
{
|
||||
"condition": "The issue requires hardware replacement.",
|
||||
"next_agent": null,
|
||||
"action": "Coordinate hardware replacement with the customer and resolve the issue."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user