July 5, 2023

Chain LLM calls

We’ve introduced sessions to Humanloop, allowing you to link multiple calls together when building a chain or agent.

Using sessions with your LLM calls helps you troubleshoot and improve your chains and agents.

Trace of an Agent's steps logged as a session

Adding a datapoint to a session

To log your LLM calls to a session, you just need to define a unique identifier for the session and pass it into your Humanloop calls with session_reference_id.

For example, using uuid4() to generate this ID,

1import uuid
2session_reference_id = str(uuid.uuid4())
3
4response = humanloop.complete(
5 project="sessions_example_assistant",
6 model_config={
7 "prompt_template": "Question: {{user_request}}\nGoogle result: {{google_answer}}\nAnswer:\n",
8 "model": "text-davinci-002",
9 "temperature": 0,
10 },
11 inputs={"user_request": user_request, "google_answer": google_answer},
12 session_reference_id=session_reference_id,
13)

Similarly, our other methods such as humanloop.complete_deployed(), humanloop.chat(), and humanloop.log() etc. support session_reference_id.

If you’re using our API directly, you can pass session_reference_id within the request body in your POST /v4/completion etc. endpoints.

Further details

For a more detailed walkthrough on how to use session_reference_id, check out our guide that runs through how to record datapoints to a session in an example script.