11---
2- title : " Agent Run Logs API "
3- sidebarTitle : " Agent Run Logs "
2+ title : " Retrieving Traces "
3+ sidebarTitle : " Retrieving Traces "
44icon : " list"
55iconType : " solid"
66---
77
8- <Warning >
9- This endpoint is currently in ** ALPHA** status and is subject to change. We welcome your feedback to help improve this API.
10- </Warning >
11-
128The Agent Run Logs API allows you to retrieve detailed execution logs for agent runs, providing insights into the agent's thought process, tool usage, and execution flow.
139
1410## Endpoint
@@ -27,12 +23,12 @@ Authorization: Bearer YOUR_API_TOKEN
2723
2824## Parameters
2925
30- | Parameter | Type | Required | Description |
31- | -----------| ------| ---------- | -------------|
32- | ` org_id ` | integer | Yes | Your organization ID |
33- | ` agent_run_id ` | integer | Yes | The ID of the agent run to retrieve logs for |
34- | ` skip ` | integer | No | Number of logs to skip for pagination (default: 0) |
35- | ` limit ` | integer | No | Maximum number of logs to return (default: 100, max: 100) |
26+ | Parameter | Type | Required | Description |
27+ | -------------- | ------- | -------- | -- ------------------------------------------------------- |
28+ | ` org_id ` | integer | Yes | Your organization ID |
29+ | ` agent_run_id ` | integer | Yes | The ID of the agent run to retrieve logs for |
30+ | ` skip ` | integer | No | Number of logs to skip for pagination (default: 0) |
31+ | ` limit ` | integer | No | Maximum number of logs to return (default: 100, max: 100) |
3632
3733## Response Structure
3834
@@ -80,25 +76,25 @@ Each log entry in the `logs` array contains the following fields:
8076
8177### Core Fields
8278
83- | Field | Type | Description |
84- | -------| ------| -------------|
85- | ` agent_run_id ` | integer | The ID of the agent run this log belongs to |
86- | ` created_at ` | string | ISO 8601 timestamp when the log entry was created |
87- | ` message_type ` | string | The type of log entry (see [ Log Types] ( #log-types ) below) |
79+ | Field | Type | Description |
80+ | -------------- | ------- | --------------------------------------------------------- |
81+ | ` agent_run_id ` | integer | The ID of the agent run this log belongs to |
82+ | ` created_at ` | string | ISO 8601 timestamp when the log entry was created |
83+ | ` message_type ` | string | The type of log entry (see [ Log Types] ( #log-types ) below) |
8884
8985### Agent Reasoning Fields
9086
91- | Field | Type | Description |
92- | -------| ------| -------------|
87+ | Field | Type | Description |
88+ | --------- | -------------- | --------------------------------------------------------------- |
9389| ` thought ` | string \| null | The agent's internal reasoning or thought process for this step |
9490
9591### Tool Execution Fields
9692
97- | Field | Type | Description |
98- | -------| ------| -------------|
99- | ` tool_name ` | string \| null | Name of the tool being executed (e.g., "ripgrep_search", "file_write") |
100- | ` tool_input ` | object \| null | JSON object containing the parameters passed to the tool |
101- | ` tool_output ` | object \| null | JSON object containing the tool's execution results |
93+ | Field | Type | Description |
94+ | ------------- | ------------------------ | ------------------------------------------------------------------------------ |
95+ | ` tool_name ` | string \| null | Name of the tool being executed (e.g., "ripgrep_search", "file_write") |
96+ | ` tool_input ` | object \| null | JSON object containing the parameters passed to the tool |
97+ | ` tool_output ` | object \| null | JSON object containing the tool's execution results |
10298| ` observation ` | object \| string \| null | The agent's observation of the tool execution results or other contextual data |
10399
104100## Log Types
@@ -107,58 +103,62 @@ The `message_type` field indicates the type of log entry. Here are the possible
107103
108104### Plan Agent Types
109105
110- | Type | Description |
111- | ------| -------------|
112- | ` ACTION ` | The agent is executing a tool or taking an action |
113- | ` PLAN_EVALUATION ` | The agent is evaluating or updating its plan |
114- | ` FINAL_ANSWER ` | The agent is providing its final response or conclusion |
115- | ` ERROR ` | An error occurred during execution |
116- | ` USER_MESSAGE ` | A message from the user (e.g., interruptions or additional context) |
117- | ` USER_GITHUB_ISSUE_COMMENT ` | A comment from a GitHub issue that the agent is processing |
106+ | Type | Description |
107+ | --------------------------- | ------------------------------------------------------------------- |
108+ | ` ACTION ` | The agent is executing a tool or taking an action |
109+ | ` PLAN_EVALUATION ` | The agent is evaluating or updating its plan |
110+ | ` FINAL_ANSWER ` | The agent is providing its final response or conclusion |
111+ | ` ERROR ` | An error occurred during execution |
112+ | ` USER_MESSAGE ` | A message from the user (e.g., interruptions or additional context) |
113+ | ` USER_GITHUB_ISSUE_COMMENT ` | A comment from a GitHub issue that the agent is processing |
118114
119115### PR Agent Types
120116
121- | Type | Description |
122- | ------| -------------|
123- | ` INITIAL_PR_GENERATION ` | The agent is generating the initial pull request |
124- | ` DETECT_PR_ERRORS ` | The agent is detecting errors in a pull request |
125- | ` FIX_PR_ERRORS ` | The agent is fixing errors found in a pull request |
126- | ` PR_CREATION_FAILED ` | Pull request creation failed |
127- | ` PR_EVALUATION ` | The agent is evaluating a pull request |
117+ | Type | Description |
118+ | ----------------------- | -------------------------------------------------- |
119+ | ` INITIAL_PR_GENERATION ` | The agent is generating the initial pull request |
120+ | ` DETECT_PR_ERRORS ` | The agent is detecting errors in a pull request |
121+ | ` FIX_PR_ERRORS ` | The agent is fixing errors found in a pull request |
122+ | ` PR_CREATION_FAILED ` | Pull request creation failed |
123+ | ` PR_EVALUATION ` | The agent is evaluating a pull request |
128124
129125### Commit Agent Types
130126
131- | Type | Description |
132- | ------| -------------|
127+ | Type | Description |
128+ | ------------------- | ------------------------------- |
133129| ` COMMIT_EVALUATION ` | The agent is evaluating commits |
134130
135131### Link Types
136132
137- | Type | Description |
138- | ------| -------------|
133+ | Type | Description |
134+ | ---------------- | ----------------------------------- |
139135| ` AGENT_RUN_LINK ` | A link to another related agent run |
140136
141137## Field Population Patterns
142138
143139Different log types populate different fields:
144140
145141### ACTION Logs
142+
146143- Always have: ` tool_name ` , ` tool_input ` , ` tool_output `
147144- Often have: ` thought ` , ` observation `
148145- Example: Tool executions like searching code, editing files, creating PRs
149146
150147### PLAN_EVALUATION Logs
148+
151149- Always have: ` thought `
152150- May have: ` observation `
153151- Rarely have: Tool-related fields
154152- Example: Agent reasoning about next steps
155153
156154### ERROR Logs
155+
157156- Always have: ` observation ` (containing error details)
158157- May have: ` tool_name ` (if error occurred during tool execution)
159158- Example: Failed tool executions or system errors
160159
161160### FINAL_ANSWER Logs
161+
162162- Always have: ` observation ` (containing the final response)
163163- May have: ` thought `
164164- Example: Agent's final response to the user
@@ -208,12 +208,12 @@ while True:
208208 url = f " https://api.codegen.com/v1/organizations/67890/agent/run/12345/logs?skip= { skip} &limit= { limit} "
209209 response = requests.get(url, headers = headers)
210210 data = response.json()
211-
211+
212212 all_logs.extend(data[' logs' ])
213-
213+
214214 if len (data[' logs' ]) < limit:
215215 break # No more logs
216-
216+
217217 skip += limit
218218
219219print (f " Retrieved { len (all_logs)} total logs " )
@@ -234,26 +234,34 @@ for error_log in error_logs:
234234## Common Use Cases
235235
236236### 1. Building Monitoring Dashboards
237+
237238Use the logs to create dashboards showing:
239+
238240- Agent execution progress
239241- Tool usage patterns
240242- Error rates and types
241243- Execution timelines
242244
243245### 2. Debugging Agent Behavior
246+
244247Analyze logs to understand:
248+
245249- Why an agent made certain decisions
246250- Where errors occurred in the execution flow
247251- What tools were used and their results
248252
249253### 3. Audit and Compliance
254+
250255Track agent actions for:
256+
251257- Code change auditing
252258- Compliance reporting
253259- Security monitoring
254260
255261### 4. Performance Analysis
262+
256263Monitor:
264+
257265- Tool execution times
258266- Common failure patterns
259267- Agent reasoning efficiency
@@ -265,13 +273,13 @@ Monitor:
265273
266274## Error Responses
267275
268- | Status Code | Description |
269- | ------------- | -------------|
270- | 400 | Bad Request - Invalid parameters |
271- | 401 | Unauthorized - Invalid or missing API token |
272- | 403 | Forbidden - Insufficient permissions |
273- | 404 | Not Found - Agent run not found |
274- | 429 | Too Many Requests - Rate limit exceeded |
276+ | Status Code | Description |
277+ | ----------- | -- ----------------------------------------- |
278+ | 400 | Bad Request - Invalid parameters |
279+ | 401 | Unauthorized - Invalid or missing API token |
280+ | 403 | Forbidden - Insufficient permissions |
281+ | 404 | Not Found - Agent run not found |
282+ | 429 | Too Many Requests - Rate limit exceeded |
275283
276284## Feedback and Support
277285
@@ -282,6 +290,6 @@ Since this endpoint is in ALPHA, we'd love your feedback! Please reach out throu
282290- Email: support@codegen.com
283291
284292<Note >
285- The structure and fields of this API may change as we gather feedback and improve the service. We'll provide advance notice of any breaking changes.
293+ The structure and fields of this API may change as we gather feedback and
294+ improve the service. We'll provide advance notice of any breaking changes.
286295</Note >
287-
0 commit comments