Attribute a response from an agent run
Use this method to attribute a response from a completed SeekrFlow agent thread. The SDK automatically extracts the context, query, and response from the thread.Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
thread_id | string | Required | ID of the agent thread to analyze. |
run_id | string | Latest | ID of the specific run to analyze. Defaults to the most recent completed run in the thread. |
granularity | string | "sentence" | How to split context into sources: "sentence" or "chunk". Sentence-level is more precise; chunk-level is faster for large contexts. |
top_k | int | 5 | Number of top sources returned per response segment. |
highlight | string | — | A specific portion of the response text to attribute. When set, returns sources for that text only rather than attributing the full response. |
num_ablations | int | Auto | Number of ablation experiments to run. Auto-computed based on context size if not set. Must be 32–256 if specified. |
Attribute raw context
Use this method when you have context, query, and response as text strings—for example, when running attribution outside of SeekrFlow agents or in a custom pipeline.Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
context | string | Required | The context text provided to the model. |
query | string | Required | The user’s query. |
response | string | Required | The model’s response to attribute. |
granularity | string | "sentence" | How to split context into sources: "sentence" or "paragraph". |
top_k | int | 5 | Number of top sources returned per response segment. |
highlight | string | — | A specific portion of the response to attribute. When set, returns sources for that text only. |
num_ablations | int | Auto | Number of ablation experiments. Auto-computed if not set. Must be 32–256 if specified. |
Response structure
Both methods return the same structure:Fields
response_text(string): The full response text that was attributed.segments(list): Per-segment attribution results. Populated whenhighlightis not provided. Each item contains:segment_index(int): 0-based position of the segment in the response.segment_text(string): The text of this segment.char_offset(int): Character offset of this segment withinresponse_text.sources(list): Sources attributed to this segment, each with:source_type(string): Either"raw"(plain context text) or"tool_response"(output from a tool call).id(int): Index of this source in the partitioned context.text(string): The source text content.attribution(float): Attribution score. See Attribution scores.offset(int): Character offset of this source in the original context.tool_name,tool_call_id,tool(tool_response only): The tool name, call ID, and tool-specific metadata. Thetoolobject varies by type:file_searchincludesfile_path,file_id, andquery;web_searchincludesurl,title, andsearch_query;code_interpreterincludescode;customincludestool_name.
sources(list): Only populated whenhighlightis provided. Contains sources for the highlighted text instead of per-segment results.highlight(string): The highlighted text echoed back, if provided in the request.
Attribution scores
Each source has anattribution value between -1 and 1. Positive values indicate the source supported the response—removing it would have caused the output to change. Values near 0 indicate little influence. Negative values are uncommon and indicate the source may have had a conflicting effect on the output.
Attribute a specific portion of the response
Passhighlight to focus attribution on one sentence or phrase. When highlight is set, segments is empty and sources are returned in the top-level sources field:
Common errors
- 400 Bad request – A required parameter is missing or invalid.
- 404 Not found – The thread or run ID does not exist.
- 422 Unprocessable entity – The thread has no assistant response. This occurs if response generation is still in progress or the agent run failed.
- 503 Service unavailable – The request timed out. Retry, or reduce context size.
- 500 Internal server error – Unexpected server error. Retry the request.
Best practices
- Granularity: Sentence-level gives the most interpretable results. When context is large and speed matters more than precision, use
"chunk"withget_context_attribution_from_runor"paragraph"withget_context_attribution. - top_k: Values of 3–5 work well for most use cases. Increase toward 10 when debugging multi-hop answers where many sources contribute.
- num_ablations: Leave unset in production. Override only when benchmarking or reproducing a specific result.
- Segments with no strong sources: This indicates the model generated that content from prior knowledge rather than retrieved context. It is expected behavior, not an error.