Skip to content

Commit d3f5faa

Browse files
tulga-bytesTulga Tsogtgerel
andauthored
python sdk examples added (#39)
Co-authored-by: Tulga Tsogtgerel <[email protected]>
1 parent 894c0a6 commit d3f5faa

15 files changed

+2278
-0
lines changed

examples/python-sdk/README.md

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
# Augment SDK Examples
2+
3+
This directory contains examples demonstrating how to use the Augment Python SDK.
4+
5+
## Basic Examples
6+
7+
### `basic_usage.py`
8+
Demonstrates fundamental SDK features:
9+
- Creating an agent
10+
- Simple text responses
11+
- Typed responses (int, bool, list, dict)
12+
- Dataclass results
13+
- Enum results
14+
- Accessing model explanations
15+
- Session management
16+
17+
**Run it:**
18+
```bash
19+
python examples/basic_usage.py
20+
```
21+
22+
### `session_usage.py`
23+
Shows how to use sessions for conversation continuity:
24+
- Default behavior (independent calls)
25+
- Session behavior (calls remember each other)
26+
- Continuing sessions automatically
27+
- Working with multiple sessions
28+
29+
**Run it:**
30+
```bash
31+
python examples/session_usage.py
32+
```
33+
34+
### `list_prs.py` / `list_prs_2.py`
35+
Examples of working with GitHub PRs using the SDK.
36+
37+
**Run them:**
38+
```bash
39+
python examples/list_prs.py
40+
python examples/list_prs_2.py
41+
```
42+
43+
## ACP Client Examples
44+
45+
### `acp_example_usage.py`
46+
Demonstrates the AuggieACPClient for persistent sessions with the Augment CLI:
47+
- Starting and stopping the agent
48+
- Sending messages with automatic context sharing
49+
- Using event listeners
50+
- Context managers
51+
52+
**Run it:**
53+
```bash
54+
python examples/acp_example_usage.py
55+
```
56+
57+
### Claude Code Client Tests
58+
59+
For ClaudeCodeACPClient examples and testing, see the **real E2E tests**:
60+
61+
**Location:** `tests/test_claude_code_client_e2e.py`
62+
63+
**Prerequisites:**
64+
```bash
65+
npm install -g @zed-industries/claude-code-acp
66+
export ANTHROPIC_API_KEY=...
67+
```
68+
69+
**Run tests:**
70+
```bash
71+
# Quick tests (~30 seconds)
72+
pytest tests/test_claude_code_client_e2e.py
73+
74+
# All tests including slow ones (~5-10 minutes)
75+
pytest tests/test_claude_code_client_e2e.py -m ""
76+
```
77+
78+
**Documentation:**
79+
- [Claude Code Client Guide](../docs/CLAUDE_CODE_CLIENT.md)
80+
- [Testing Guide](../tests/README_CLAUDE_CODE_TESTS.md)
81+
82+
## Prompt-to-SDK Conversion
83+
84+
### `example_complex_prompt.txt`
85+
A sample complex prompt that demonstrates multiple stages, conditions, and iterations. Use this to test the `/prompt-to-sdk` command.
86+
87+
**Example prompt structure:**
88+
```
89+
Analyze all TypeScript files in clients/beachhead/src/cli.
90+
91+
For each file:
92+
1. Check if it has proper error handling
93+
2. Check if it has JSDoc comments
94+
3. Identify potential bugs
95+
96+
After analyzing all files:
97+
1. Create a summary report
98+
2. If >5 files missing error handling, create a plan
99+
3. If >10 files missing JSDoc, generate templates
100+
101+
Finally:
102+
- Count total issues
103+
- Prioritize top 3 critical issues
104+
- Create fix suggestions for top 3
105+
```
106+
107+
**Convert it to SDK code:**
108+
```bash
109+
# In TUI mode
110+
/prompt-to-sdk examples/example_complex_prompt.txt
111+
112+
# From command line
113+
auggie command prompt-to-sdk examples/example_complex_prompt.txt
114+
```
115+
116+
### `demo_prompt_to_sdk.sh`
117+
Interactive demo script that shows the prompt-to-sdk conversion process.
118+
119+
**Run it:**
120+
```bash
121+
./examples/demo_prompt_to_sdk.sh
122+
```
123+
124+
## Workflow Patterns
125+
126+
The examples demonstrate these common patterns:
127+
128+
### 1. Sequential Workflow
129+
```python
130+
with agent.session() as session:
131+
session("Step 1")
132+
session("Step 2 that builds on step 1")
133+
session("Step 3 that uses both")
134+
```
135+
136+
### 2. Conditional Logic
137+
```python
138+
exists = agent("Does file exist?", bool)
139+
if exists:
140+
agent("Process existing file")
141+
else:
142+
agent("Create new file")
143+
```
144+
145+
### 3. Iteration with Structured Data
146+
```python
147+
@dataclass
148+
class FileInfo:
149+
path: str
150+
size: int
151+
152+
files = agent("Analyze files", list[FileInfo])
153+
for file in files:
154+
if file.size > 1000:
155+
agent(f"Optimize {file.path}")
156+
```
157+
158+
### 4. Function Calling
159+
```python
160+
def run_tests(test_file: str) -> dict:
161+
"""
162+
Run tests from a test file.
163+
164+
Args:
165+
test_file: Path to the test file
166+
"""
167+
# Your test logic
168+
return {"passed": 10, "failed": 2, "file": test_file}
169+
170+
# Agent can call the function as needed
171+
result = agent.run(
172+
"Run tests in test_auth.py and analyze the results",
173+
return_type=dict,
174+
functions=[run_tests]
175+
)
176+
```
177+
178+
### 5. Error Handling
179+
```python
180+
from auggie_sdk.exceptions import AugmentCLIError, AugmentParseError
181+
182+
try:
183+
result = agent("Complex task", int)
184+
except AugmentParseError:
185+
print("Could not parse result")
186+
except AugmentCLIError:
187+
print("Agent execution failed")
188+
```
189+
190+
## Creating Your Own Examples
191+
192+
### Simple Script Template
193+
```python
194+
#!/usr/bin/env python3
195+
"""
196+
Description of what this script does.
197+
"""
198+
199+
from auggie_sdk import Auggie
200+
201+
def main():
202+
# Create agent
203+
agent = Auggie(workspace_root=".", model="claude-3-5-sonnet-latest")
204+
205+
# Your workflow here
206+
result = agent("Your instruction")
207+
print(f"Result: {result}")
208+
209+
if __name__ == "__main__":
210+
main()
211+
```
212+
213+
### Complex Workflow Template
214+
```python
215+
#!/usr/bin/env python3
216+
"""
217+
Multi-stage workflow with structured data.
218+
"""
219+
220+
from auggie_sdk import Auggie
221+
from dataclasses import dataclass
222+
from typing import List, Optional
223+
224+
@dataclass
225+
class YourDataClass:
226+
field1: str
227+
field2: int
228+
229+
def main():
230+
agent = Auggie(workspace_root=".", model="claude-3-5-sonnet-latest")
231+
232+
# Stage 1: Get structured data
233+
items = agent("Get items", list[YourDataClass])
234+
print(f"Found {len(items)} items")
235+
236+
# Stage 2: Process with session
237+
with agent.session() as session:
238+
for item in items:
239+
session(f"Process {item.field1}")
240+
241+
# Stage 3: Final report
242+
agent("Create summary report")
243+
print("Workflow complete!")
244+
245+
if __name__ == "__main__":
246+
main()
247+
```
248+
249+
## Testing Examples
250+
251+
All examples can be run directly:
252+
253+
```bash
254+
# Run a specific example
255+
python examples/basic_usage.py
256+
257+
# Run with custom workspace
258+
python examples/basic_usage.py --workspace /path/to/workspace
259+
260+
# Run with different model
261+
python examples/basic_usage.py --model gpt-4o
262+
```
263+
264+
## Documentation
265+
266+
- **SDK README**: `../README.md`
267+
- **Prompt-to-SDK Guide**: `../PROMPT_TO_SDK_GUIDE.md`
268+
- **Slash Command Summary**: `../SLASH_COMMAND_SUMMARY.md`
269+
270+
## Getting Help
271+
272+
If you encounter issues:
273+
274+
1. Check that the SDK is installed: `pip install -e .`
275+
2. Verify auggie CLI is available: `auggie --version`
276+
3. Check the workspace path is correct
277+
4. Review error messages for specific issues
278+
279+
For more help, see the main SDK documentation.

0 commit comments

Comments
 (0)