import { agentSpan, setup } from "@inference/tracing";
import * as CallbackManagerModule from "@langchain/core/callbacks/manager";
import { Annotation, END, START, StateGraph } from "@langchain/langgraph";
const tracing = await setup({
serviceName: "counter-graph",
modules: { langchainCallbacksManager: CallbackManagerModule },
});
const State = Annotation.Root({
count: Annotation<number>({
reducer: (_left, right) => right,
default: () => 0,
}),
});
const graph = new StateGraph(State)
.addNode("increment", (state) => ({ count: state.count + 1 }))
.addNode("double", (state) => ({ count: state.count * 2 }))
.addEdge(START, "increment")
.addEdge("increment", "double")
.addEdge("double", END)
.compile();
const result = await agentSpan(
{
agentId: "counter-graph-agent",
agentName: "Counter Graph Agent",
spanName: "counter-graph.run",
sessionId: "conversation-counter-1",
role: "workflow",
system: "langgraph",
},
async (span) => {
const input = { count: 1 };
span.setInput(input);
const output = await graph.invoke(input);
span.setOutput(output);
return output;
},
);
console.log(result);
await tracing.shutdown();