Skip to content

Create API to query agentic threads #1338

@dannykopping

Description

@dannykopping

Depends on #1334
Depends on #1336

Now that we have a relationship between tool calls and a "parent" interception has been established (agentic thread), we must provide an APIs to retrieve these.

Sessions are sets of interceptions (#1336) or threads.
Threads are special sets of interceptions whereby an initial prompt kicked off an agent loop involving one or more tool calls.

Agentic loop:

1. Client: Prompt
     ↓
2. Server: LLM decides to use tool call
     ↓
3. Client: Invokes tool call, sends tool result
     ↓
4. Server: receives tool result, performs next inference
     - if terminal state → done
     - if another tool call required → go to 2

A thread is not an actual record, it's a logical grouping of multiple interception records.

If a session ID is not present for an interception, the individual interception should be treated as a session with a single interception and the session ID = interception ID.

Acceptance criteria:

  • Added API endpoints with same filters as /api/v2/aibridge/interceptions (plus session ID), and pagination
    • GET /api/v2/aibridge/threads/by-session (we'll use this for the new listing page)
    • GET /api/v2/aibridge/sessions/:id/threads (just an alias for GET /api/v2/aibridge/threads/by-session?session-id={id}, displaying only a single session - no list)
    • GET /api/v2/aibridge/threads/:id
      • Database queries added to facilitate these
  • Tests added

GET /api/v2/aibridge/threads/by-session
{
    "count": 99,
    "sessions": [
        {
            "session_id": "session_id|interception_id",
            "threads": [
                {
                    "api_key_id": "string",
                    "started_at": "2019-08-24T14:15:22Z", // started_at of first interception
                    "ended_at": "2019-08-24T14:15:22Z", // ended_at of last interception
                    "provider": "string",
                    "models": ["string", "string"],
                    "prompt": "string",
                    "initiator": {
                        "avatar_url": "http://example.com",
                        "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
                        "name": "string",
                        "username": "string"
                    },
                    "tokens_total": {
                        "input": 123, // input + cache reads
                        "output": 456
                    },
                    "tool_calls_total": 5
                }
            ]
        }
    ]
}

TODO: add other API response payloads

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions