@intentsolutionsio/ai-sdk-agents 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Agent Template
3
+ *
4
+ * This file provides a template for creating new agents within the ai-sdk-agents plugin.
5
+ * Use this as a starting point to define the behavior and capabilities of your agent.
6
+ *
7
+ * Instructions:
8
+ * 1. Replace the placeholder values with your agent's specific details.
9
+ * 2. Implement the `execute` method to define the agent's core logic.
10
+ * 3. Define the agent's tools and capabilities using the `AgentCapabilities` interface.
11
+ * 4. Ensure your agent properly handles errors and exceptions.
12
+ * 5. Consider adding logging and monitoring for improved observability.
13
+ */
14
+
15
+ import { Agent, AgentCapabilities, AgentContext } from '@ai-sdk/core'; // Replace with actual import path if needed
16
+
17
+ // Define the specific capabilities of this agent. Adjust as needed.
18
+ interface MyAgentCapabilities extends AgentCapabilities {
19
+ [key: string]: any; // Allows for flexible capability definitions. Consider more specific types.
20
+ // Example:
21
+ // summarizeText: (text: string) => Promise<string>;
22
+ // translateText: (text: string, targetLanguage: string) => Promise<string>;
23
+ }
24
+
25
+ /**
26
+ * MyAgent Class
27
+ *
28
+ * A template for creating new AI agents.
29
+ */
30
+ export class MyAgent implements Agent<MyAgentCapabilities> {
31
+ // Agent Name (Required)
32
+ name: string = "MyAgentName";
33
+
34
+ // Agent Description (Required)
35
+ description: string = "A brief description of what this agent does.";
36
+
37
+ // (Optional) Specific instructions or persona for the agent
38
+ instructions?: string = "You are a helpful assistant...";
39
+
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @param capabilities - The capabilities of the agent (tools, functions, etc.).
45
+ */
46
+ constructor(public capabilities: MyAgentCapabilities) {
47
+ // Initialization logic can go here.
48
+ }
49
+
50
+
51
+ /**
52
+ * Execute Method
53
+ *
54
+ * This is the core logic of the agent. It receives the user's input and the agent's context.
55
+ *
56
+ * @param input - The user's input.
57
+ * @param context - The agent's context (access to other agents, data, etc.).
58
+ * @returns A promise that resolves to the agent's response.
59
+ */
60
+ async execute(input: string, context: AgentContext): Promise<string> {
61
+ try {
62
+ // Implement your agent's logic here.
63
+ // Example:
64
+ // const summary = await this.capabilities.summarizeText(input);
65
+ // return summary;
66
+
67
+ // Placeholder response:
68
+ return `Agent ${this.name} received input: ${input}. This is a placeholder response.`;
69
+
70
+ } catch (error: any) {
71
+ console.error(`Error in agent ${this.name}:`, error);
72
+ return `Agent ${this.name} encountered an error: ${error.message || error}`;
73
+ }
74
+ }
75
+ }
76
+
77
+
78
+ /**
79
+ * Example Usage (for testing/demonstration purposes)
80
+ */
81
+ async function main() {
82
+ // Example capabilities (replace with actual implementations)
83
+ const myCapabilities: MyAgentCapabilities = {
84
+ // Example:
85
+ // summarizeText: async (text: string) => `Summarized: ${text.substring(0, 50)}...`,
86
+ // translateText: async (text: string, targetLanguage: string) => `Translated to ${targetLanguage}: ${text}`,
87
+ };
88
+
89
+ const myAgent = new MyAgent(myCapabilities);
90
+
91
+ const context: AgentContext = {
92
+ getAgent: async (name: string) => {
93
+ console.warn(`Attempted to get agent ${name}, but no other agents are defined in this example.`);
94
+ return undefined;
95
+ },
96
+ getPluginData: async (key: string) => {
97
+ console.warn(`Attempted to get plugin data for key ${key}, but no plugin data is defined in this example.`);
98
+ return undefined;
99
+ },
100
+
101
+ };
102
+
103
+ const userInput = "This is a test input for the agent.";
104
+ const response = await myAgent.execute(userInput, context);
105
+
106
+ console.log("Agent Response:", response);
107
+ }
108
+
109
+ // Run the example (optional - remove in production)
110
+ // main();
@@ -0,0 +1,100 @@
1
+ // example_coordinator.ts
2
+
3
+ /**
4
+ * This file provides an example implementation of a coordinator agent using the AI SDK.
5
+ * Coordinator agents are responsible for routing requests to specialized agents and
6
+ * managing the overall workflow of a multi-agent system.
7
+ *
8
+ * This example demonstrates basic routing logic. You can customize this to fit your specific use case.
9
+ */
10
+
11
+ import { Agent, AgentContext, AgentOutput, AgentConfig } from "@ai-sdk/core"; // Replace with actual import path if needed
12
+
13
+ // Define the interface for the agent's input. Customize this based on what your agents need.
14
+ interface CoordinatorInput {
15
+ query: string;
16
+ // Add other relevant input parameters here
17
+ }
18
+
19
+ // Define the interface for the agent's output. Customize this based on your needs.
20
+ interface CoordinatorOutput extends AgentOutput {
21
+ response: string;
22
+ routedToAgent?: string; // Optional: Indicate which agent handled the request
23
+ }
24
+
25
+ // Define the configuration options for the coordinator agent.
26
+ interface CoordinatorConfig extends AgentConfig {
27
+ // Add any configuration options specific to the coordinator agent here, such as:
28
+ // - List of available agents and their descriptions
29
+ // - Routing rules
30
+ // - Error handling strategies
31
+ agent1: Agent; // Define agent1
32
+ agent2: Agent; // Define agent2
33
+ }
34
+
35
+ // Implement the coordinator agent class.
36
+ class CoordinatorAgent implements Agent<CoordinatorInput, CoordinatorOutput, CoordinatorConfig> {
37
+ config: CoordinatorConfig;
38
+
39
+ constructor(config: CoordinatorConfig) {
40
+ this.config = config;
41
+ }
42
+
43
+ async execute(input: CoordinatorInput, context: AgentContext): Promise<CoordinatorOutput> {
44
+ const { query } = input;
45
+
46
+ // Implement your routing logic here. This is a simplified example.
47
+ // Consider using more sophisticated methods like:
48
+ // - Natural language understanding to determine the intent of the query
49
+ // - A knowledge base to match the query to the appropriate agent
50
+ // - A machine learning model to predict the best agent to handle the request
51
+
52
+ let routedToAgent: Agent | null = null;
53
+ let agentName: string | undefined = undefined;
54
+
55
+ if (query.toLowerCase().includes("agent1")) {
56
+ routedToAgent = this.config.agent1;
57
+ agentName = "Agent1";
58
+ } else if (query.toLowerCase().includes("agent2")) {
59
+ routedToAgent = this.config.agent2;
60
+ agentName = "Agent2";
61
+ } else {
62
+ // Default routing logic - you should customize this
63
+ routedToAgent = this.config.agent1; // Example: Default to agent1
64
+ agentName = "Agent1";
65
+ }
66
+
67
+
68
+ if (!routedToAgent) {
69
+ return {
70
+ response: "Error: No suitable agent found to handle the request.",
71
+ };
72
+ }
73
+
74
+ // Execute the selected agent.
75
+ const agentOutput: any = await routedToAgent.execute({ query: query }, context); // Replace 'any' with the actual expected output type from the agent.
76
+
77
+ // Process the output from the selected agent and format it as the coordinator's output.
78
+ return {
79
+ response: `[${agentName ?? "Unknown Agent"}] ${agentOutput.response}`, // Customize formatting as needed
80
+ routedToAgent: agentName,
81
+ // Include any other relevant information in the output
82
+ };
83
+ }
84
+ }
85
+
86
+ export { CoordinatorAgent, CoordinatorInput, CoordinatorOutput, CoordinatorConfig };
87
+
88
+ // Example Usage (in another file):
89
+ // import { CoordinatorAgent, CoordinatorConfig } from './example_coordinator';
90
+ // import { Agent1, Agent2 } from './your_agents'; // Assuming you have Agent1 and Agent2 defined
91
+
92
+ // const config: CoordinatorConfig = {
93
+ // agent1: new Agent1(),
94
+ // agent2: new Agent2(),
95
+ // // ... other configuration options
96
+ // };
97
+
98
+ // const coordinator = new CoordinatorAgent(config);
99
+ // const result = await coordinator.execute({ query: "Route this to agent1" }, context);
100
+ // console.log(result.response);
@@ -0,0 +1,143 @@
1
+ {
2
+ "_comment": "Example workflow definition for a multi-agent system powered by AI SDK v5.",
3
+ "workflow_name": "Customer Service and Issue Resolution",
4
+ "description": "A workflow that handles customer inquiries, escalates issues to specialists, and provides final resolutions.",
5
+ "agents": [
6
+ {
7
+ "agent_id": "customer_service_agent",
8
+ "name": "Customer Service Agent",
9
+ "description": "First point of contact for all customer inquiries. Triages requests and routes them to appropriate specialists.",
10
+ "model_provider": "anthropic",
11
+ "model_name": "claude-3-opus-20240229",
12
+ "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.",
13
+ "initial_state": true,
14
+ "routing_rules": [
15
+ {
16
+ "condition": "The customer's issue is related to billing or payment.",
17
+ "next_agent": "billing_specialist",
18
+ "action": "Summarize the billing issue and forward it to the Billing Specialist."
19
+ },
20
+ {
21
+ "condition": "The customer's issue is technical and requires expert assistance.",
22
+ "next_agent": "technical_support_agent",
23
+ "action": "Summarize the technical issue and forward it to the Technical Support Agent."
24
+ },
25
+ {
26
+ "condition": "The customer is requesting information about products or services.",
27
+ "next_agent": "sales_agent",
28
+ "action": "Forward the inquiry to the Sales Agent."
29
+ },
30
+ {
31
+ "condition": "The customer's issue can be resolved with readily available information.",
32
+ "next_agent": null,
33
+ "action": "Answer the customer's question directly and end the interaction."
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "agent_id": "billing_specialist",
39
+ "name": "Billing Specialist",
40
+ "description": "Handles all billing and payment-related inquiries. Resolves billing disputes and provides payment options.",
41
+ "model_provider": "openai",
42
+ "model_name": "gpt-4-turbo-preview",
43
+ "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.",
44
+ "routing_rules": [
45
+ {
46
+ "condition": "The billing issue is complex and requires managerial approval.",
47
+ "next_agent": "billing_manager",
48
+ "action": "Summarize the issue and forward it to the Billing Manager."
49
+ },
50
+ {
51
+ "condition": "The billing issue can be resolved.",
52
+ "next_agent": null,
53
+ "action": "Resolve the billing issue and notify the customer."
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "agent_id": "technical_support_agent",
59
+ "name": "Technical Support Agent",
60
+ "description": "Provides technical assistance to customers. Diagnoses and resolves technical issues.",
61
+ "model_provider": "google",
62
+ "model_name": "gemini-1.5-pro",
63
+ "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.",
64
+ "routing_rules": [
65
+ {
66
+ "condition": "The technical issue requires a software update.",
67
+ "next_agent": null,
68
+ "action": "Guide the customer through the software update process and verify the resolution."
69
+ },
70
+ {
71
+ "condition": "The technical issue is beyond your expertise.",
72
+ "next_agent": "escalation_team",
73
+ "action": "Escalate the issue to the escalation team with a detailed description."
74
+ },
75
+ {
76
+ "condition": "The technical issue is resolved.",
77
+ "next_agent": null,
78
+ "action": "Confirm the resolution with the customer and close the ticket."
79
+ }
80
+ ]
81
+ },
82
+ {
83
+ "agent_id": "sales_agent",
84
+ "name": "Sales Agent",
85
+ "description": "Provides information about products and services and assists with sales inquiries.",
86
+ "model_provider": "anthropic",
87
+ "model_name": "claude-3-opus-20240229",
88
+ "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.",
89
+ "routing_rules": [
90
+ {
91
+ "condition": "The customer is ready to make a purchase.",
92
+ "next_agent": null,
93
+ "action": "Guide the customer through the purchase process."
94
+ },
95
+ {
96
+ "condition": "The customer has specific product questions.",
97
+ "next_agent": null,
98
+ "action": "Answer the customer's questions and provide relevant information."
99
+ }
100
+ ]
101
+ },
102
+ {
103
+ "agent_id": "billing_manager",
104
+ "name": "Billing Manager",
105
+ "description": "Handles escalated billing issues that require managerial approval.",
106
+ "model_provider": "openai",
107
+ "model_name": "gpt-4-turbo-preview",
108
+ "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.",
109
+ "routing_rules": [
110
+ {
111
+ "condition": "The issue requires further investigation.",
112
+ "next_agent": null,
113
+ "action": "Investigate the issue and make a final decision."
114
+ },
115
+ {
116
+ "condition": "The issue can be resolved with an exception.",
117
+ "next_agent": null,
118
+ "action": "Approve the exception and resolve the billing issue."
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ "agent_id": "escalation_team",
124
+ "name": "Escalation Team",
125
+ "description": "Handles complex technical issues that require specialized expertise.",
126
+ "model_provider": "google",
127
+ "model_name": "gemini-1.5-pro",
128
+ "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.",
129
+ "routing_rules": [
130
+ {
131
+ "condition": "The issue requires a code fix.",
132
+ "next_agent": null,
133
+ "action": "Develop and deploy a code fix to resolve the issue."
134
+ },
135
+ {
136
+ "condition": "The issue requires hardware replacement.",
137
+ "next_agent": null,
138
+ "action": "Coordinate hardware replacement with the customer and resolve the issue."
139
+ }
140
+ ]
141
+ }
142
+ ]
143
+ }
@@ -0,0 +1,4 @@
1
+ # References
2
+
3
+ Bundled resources for ai-sdk-agents skill
4
+
@@ -0,0 +1,26 @@
1
+ # Error Handling Reference
2
+
3
+ Common issues and solutions:
4
+
5
+ **Agent Initialization Failures**
6
+ - Error: AI SDK provider configuration invalid
7
+ - Solution: Verify API keys in environment variables, check provider-specific setup requirements
8
+
9
+ **Handoff Execution Errors**
10
+ - Error: Agent handoff fails or creates circular dependencies
11
+ - Solution: Review handoff rules for clarity, implement handoff depth limits, add fallback agents
12
+
13
+ **Routing Logic Failures**
14
+ - Error: Tasks routed to incorrect agent or no agent
15
+ - Solution: Refine routing criteria, add default routing rules, implement topic classification improvement
16
+
17
+ **Tool Access Violations**
18
+ - Error: Agent attempts to use unauthorized tools
19
+ - Solution: Review tool permissions per agent, implement proper access control, validate tool configurations
20
+
21
+ **Workflow Deadlocks**
22
+ - Error: Multi-agent workflow stalls without completion
23
+ - Solution: Implement timeout mechanisms, add workflow monitoring, design escape conditions for stuck states
24
+
25
+ ---
26
+ *[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*