Before you start logging you will have to create a LogRepository on the Maxim dashboard. To create a log repository,click on Logs and the
click on + icon on the sidebar. You can use the ID of that repository to push logs.
const session = logger.session({ id: "session-id", // required name: "session-name", // optional tags: { key: "value" }, // optional, you can filter logs based on metadata});
Once session object is created, you can add multiple Traces across the lifecycle of the conversation.
Adding a Trace to a Session
const session = logger.session({ id: "session-id" });// Here if the trace with the same id is available, it will return the same trace object else create a new one.const trace = session.trace({ id: "trace-id" });
// ... in function 1const trace = logger.trace({ id: "trace-id" });// ... in function 2const trace = logger.trace({ id: "trace-id" });// it returns the same trace objecttrace.addTag({ key: "value" });
// ... in function 1const session = logger.session({ id: "session-id" });// ... in function 2const session = logger.session({ id: "session-id" });// it returns the same session objectsession.addTag({ key: "value" });
A Tool Call is a special type of Span in Maxim, which represents an external system or service call done based on an LLM response.
Adding a Tool Call to a Trace
const toolCall = completion.choices[0].message.tool_calls[0];const traceToolCall = trace.toolCall({ id: toolCall.id, name: toolCall.function.name, description: "Get current temperature for a given location.", args: toolCall.function.arguments, tags: { location: toolCall.function.arguments["location"] },});const result = callExternalService(toolCall.function.name, toolCall.function.arguments);traceToolCall.result(result);
Maxim supports node-level evaluation, which allows you to evaluate each individual node in your whole trace. This evaluation can be used to measure the quality of each node's output, and can be used to improve the performance of the node.
To evaluate a node, you can use the evaluate method of the node.
Evaluating a node
// for this example we are evaluating a particular generation// but you can evaluate any node in your trace similarly// ...receive user input and process itgeneration.evaluate.withEvaluators("clarity", "toxicity").withVariables({ input: userInput,});// ...generate llm responsegeneration.evaluate.withVariables({ output: llmResponse.choices[0].message.content }, ["clarity", "toxicity"]);//...code continues
More infomation about Agentic Evaluation can be found in the Agentic Evaluation section under Observability -> Evaluating Logs.