import { trace, component } from "@agentmark/sdk";
trace(
{
name: "ai-agent-workflow",
metadata: {
"graph.node.id": "orchestrator",
"graph.node.display_name": "AI Agent Orchestrator",
"graph.node.type": "router",
},
},
async () => {
// Process and validate user input
component(
{
name: "input-processor",
metadata: {
"graph.node.id": "input-processor",
"graph.node.parent_id": "orchestrator",
"graph.node.display_name": "Input Processor",
"graph.node.type": "agent",
},
},
async () => {
// Validate and clean user input, extract intent
console.log("Processing user input...");
}
);
// Retrieve relevant context from memory/database
component(
{
name: "context-retrieval",
metadata: {
"graph.node.id": "context-retrieval",
"graph.node.parent_id": "orchestrator",
"graph.node.display_name": "Context Retrieval",
"graph.node.type": "retrieval",
},
},
async () => {
// Fetch relevant context, conversation history, user preferences
console.log("Retrieving context...");
}
);
// Main LLM reasoning combining input and context
component(
{
name: "llm-reasoning",
metadata: {
"graph.node.id": "llm-reasoning",
"graph.node.parent_ids": JSON.stringify(["input-processor", "context-retrieval"]),
"graph.node.display_name": "LLM Reasoning",
"graph.node.type": "llm",
},
},
async () => {
// Perform main AI reasoning with processed input and retrieved context
console.log("AI reasoning...");
}
);
// Execute tools if needed based on LLM decision
component(
{
name: "tool-executor",
metadata: {
"graph.node.id": "tool-executor",
"graph.node.parent_id": "llm-reasoning",
"graph.node.display_name": "Tool Executor",
"graph.node.type": "tool",
},
},
async () => {
// Execute external tools (API calls, calculations, etc.)
console.log("Executing tools...");
}
);
// Format the final response
component(
{
name: "response-formatter",
metadata: {
"graph.node.id": "response-formatter",
"graph.node.parent_ids": JSON.stringify(["llm-reasoning", "tool-executor"]),
"graph.node.display_name": "Response Formatter",
"graph.node.type": "agent",
},
},
async () => {
// Format the response for the user
console.log("Formatting response...");
}
);
// Store interaction in memory for future reference
component(
{
name: "memory-storage",
metadata: {
"graph.node.id": "memory-storage",
"graph.node.parent_id": "response-formatter",
"graph.node.display_name": "Memory Storage",
"graph.node.type": "memory",
},
},
async () => {
// Store the interaction, learnings, and outcomes
console.log("Storing in memory...");
}
);
}
);