Skip to content

Commit 9922bf9

Browse files
committed
fix: update schema
1 parent bd89500 commit 9922bf9

File tree

3 files changed

+128
-5
lines changed

3 files changed

+128
-5
lines changed

src/codegen/agents/README.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Codegen Agents - Python SDK
2+
3+
This module provides a Python client for interacting with the Codegen AI agents API.
4+
5+
## Installation
6+
7+
The Codegen Agent SDK is included as part of the Codegen package. Ensure you have the latest version installed:
8+
9+
```bash
10+
pip install codegen
11+
```
12+
13+
## Usage
14+
15+
### Basic Example
16+
17+
```python
18+
from codegen.agents.agent import Agent
19+
20+
# Initialize the Agent with your organization ID and API token
21+
agent = Agent(
22+
org_id="11", # Your organization ID
23+
token="your_api_token_here", # Your API authentication token
24+
base_url="https://codegen-sh-rest-api.modal.run" # Optional - defaults to this URL
25+
)
26+
27+
# Run an agent with a prompt
28+
task = agent.run(prompt="Which github repos can you currently access?")
29+
30+
# Check the initial status
31+
print(task.status) # Returns the current status of the task (e.g., "queued", "in_progress", etc.)
32+
33+
# Refresh the task to get updated status
34+
task.refresh()
35+
36+
# Check the updated status
37+
print(task.status)
38+
39+
# Once task is complete, you can access the result
40+
if task.status == "completed":
41+
print(task.result)
42+
```
43+
44+
### Agent Class
45+
46+
The `Agent` class is the main entry point for interacting with Codegen AI agents:
47+
48+
```python
49+
Agent(token: str, org_id: Optional[int] = None, base_url: Optional[str] = CODEGEN_BASE_API_URL)
50+
```
51+
52+
Parameters:
53+
- `token` (required): Your API authentication token
54+
- `org_id` (optional): Your organization ID. If not provided, defaults to environment variable `CODEGEN_ORG_ID` or "1"
55+
- `base_url` (optional): API base URL. Defaults to "https://codegen-sh-rest-api.modal.run"
56+
57+
### Methods
58+
59+
#### run()
60+
61+
```python
62+
run(prompt: str) -> AgentTask
63+
```
64+
65+
Runs an agent with the given prompt.
66+
67+
Parameters:
68+
- `prompt` (required): The instruction for the agent to execute
69+
70+
Returns:
71+
- An `AgentTask` object representing the running task
72+
73+
#### get_status()
74+
75+
```python
76+
get_status() -> Optional[Dict[str, Any]]
77+
```
78+
79+
Gets the status of the current task.
80+
81+
Returns:
82+
- A dictionary containing task status information (`id`, `status`, `result`), or `None` if no task has been run
83+
84+
### AgentTask Class
85+
86+
The `AgentTask` class represents a running or completed agent task:
87+
88+
#### Attributes
89+
90+
- `id`: The unique identifier for the task
91+
- `org_id`: The organization ID
92+
- `status`: Current status of the task (e.g., "queued", "in_progress", "completed", "failed")
93+
- `result`: The task result (available when status is "completed")
94+
95+
#### Methods
96+
97+
##### refresh()
98+
99+
```python
100+
refresh() -> None
101+
```
102+
103+
Refreshes the task status from the API.
104+
105+
## Environment Variables
106+
107+
- `CODEGEN_ORG_ID`: Default organization ID (used if `org_id` is not provided)
108+
109+
## Error Handling
110+
111+
Handle potential API errors using standard try/except blocks:
112+
113+
```python
114+
try:
115+
task = agent.run(prompt="Your prompt here")
116+
task.refresh()
117+
print(task.status)
118+
except Exception as e:
119+
print(f"Error: {e}")
120+
```

src/codegen/agents/agent.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ def __init__(self, task_data: AgentRunResponse, api_client: ApiClient, org_id: i
1717
self.org_id = org_id
1818
self.status = task_data.status
1919
self.result = task_data.result
20+
self.web_url = task_data.web_url
2021
self._api_client = api_client
2122
self._agents_api = AgentsApi(api_client)
22-
23+
2324
def refresh(self) -> None:
2425
"""Refresh the job status from the API."""
2526
if self.id is None:
@@ -81,7 +82,6 @@ def run(self, prompt: str) -> AgentTask:
8182
authorization=f"Bearer {self.token}",
8283
_headers={"Content-Type": "application/json"}
8384
)
84-
8585
# Convert API response to dict for Job initialization
8686

8787
job = AgentTask(agent_run_response, self.api_client, self.org_id)
@@ -101,6 +101,7 @@ def get_status(self) -> Optional[Dict[str, Any]]:
101101
return {
102102
"id": self.current_job.id,
103103
"status": self.current_job.status,
104-
"result": self.current_job.result
104+
"result": self.current_job.result,
105+
"web_url": self.current_job.web_url
105106
}
106107
return None

src/codegen/agents/client/openapi_client/models/agent_run_response.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class AgentRunResponse(BaseModel):
3131
status: Optional[StrictStr] = None
3232
created_at: Optional[StrictStr] = None
3333
result: Optional[StrictStr] = None
34-
__properties: ClassVar[List[str]] = ["id", "organization_id", "status", "created_at", "result"]
34+
web_url: Optional[StrictStr] = None
35+
__properties: ClassVar[List[str]] = ["id", "organization_id", "status", "created_at", "result", "web_url"]
3536

3637
model_config = ConfigDict(
3738
populate_by_name=True,
@@ -103,7 +104,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
103104
"organization_id": obj.get("organization_id"),
104105
"status": obj.get("status"),
105106
"created_at": obj.get("created_at"),
106-
"result": obj.get("result")
107+
"result": obj.get("result"),
108+
"web_url": obj.get("web_url")
107109
})
108110
return _obj
109111

0 commit comments

Comments
 (0)