Logging through API
Instrument your AI project with any programming language using the API.
Our SDK offers high-level utilities for integrating Humanloop in your project. If you use a language without SDK support, or prefer more control, you can use the API directly to the same effect.
This guide revisits our logging quickstart tutorial: we’ll use API actions instead of the SDK decorators, showing you how Humanloop instrumentation works step by step.
By the end, we’ll have a chat agent project split into versioned components and with Humanloop logging integrated.
Prerequisites
Create the chat agent
We start with a simple chat agent that answers math and science questions.
Python
TypeScript
Create an agent.py
file and add the following:
Log to Humanloop
Use the SDK to create the versionable components of the agent. Logging against a File on a given path will create the File if it does not exist. Changing the File definition will create a new version of the File.
Initialize the trace
Modify call_model
to accept a trace_id
argument. It will be used to associate Logs to the logging trace.
The trace of the conversation will be contained by a Flow. Initialize the trace at the start of the conversation.
Python
Typescript
Run the code
Have a conversation with the agent. When you’re done, type exit
to close the program.
Check your workspace
Navigate to your workspace to see the logged conversation.
Inside the Logging Quickstart directory on the left, click the QA Agent Flow. Select the Logs tab from the top of the page and click the Log inside the table.
You will see the conversation’s trace, containing Logs corresponding to the Tool and the Prompt.
Change the agent and rerun
Modify the call_model
function to use a different model and temperature.
Python
Typescript
Run the agent again, then head back to your workspace.
Click the QA Prompt Prompt, select the Dashboard tab from the top of the page and look at Uncommitted Versions.
By changing the hyperparameters of the OpenAI call, you have tagged a new version of the Prompt.
Next steps
Logging is the first step to observing your AI product. Follow up with these guides on monitoring and evals:
-
Add monitoring Evaluators to evaluate Logs as they’re made against a File.
-
Explore evals to improve the performance of your AI feature in our guide on running an Evaluation.
-
See logging in action on a complex example in our tutorial on evaluating an agent.
-
Consult our API reference for a full list of actions and their parameters.