-
Notifications
You must be signed in to change notification settings - Fork 13
Updated python-sdk example code to match the latest sdk #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR updates the Python SDK examples to match the latest SDK API. The changes are generally well-structured and improve consistency across examples. However, I found a few potential issues related to import validation and error handling that should be addressed.
🤖 Automated review complete. Please react with 👍 or 👎 on the individual review comments to provide feedback on their usefulness.
|
|
||
| # List of allowed imports (common Python stdlib + augment) | ||
| allowed_imports = { | ||
| "augment", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check_imports() function only allows "augment" in the allowed imports list, but the actual import statement used throughout the codebase is "auggie_sdk". This will cause false warnings when validating generated code that correctly imports from auggie_sdk.
allowed_imports = {
"auggie_sdk", # Add this
"augment",
"dataclasses",
# ... rest of imports
}| if alias.name not in allowed_imports: | ||
| warnings.append(f"Warning: Unexpected import '{alias.name}'") | ||
| elif isinstance(node, ast.ImportFrom): | ||
| if node.module and node.module not in allowed_imports: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import validation logic doesn't handle submodule imports correctly. For example, from auggie_sdk.acp import AuggieACPClient will check if "auggie_sdk.acp" is in the allowed list, but only "auggie_sdk" would be present. This should check the root module name.
elif isinstance(node, ast.ImportFrom):
if node.module:
# Check root module name for submodule imports
root_module = node.module.split('.')[0]
if root_module not in allowed_imports:
warnings.append(f"Warning: Unexpected import from '{node.module}'")| # Output the code | ||
| if args.output: | ||
| output_file = Path(args.output) | ||
| output_file.write_text(result.code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential AttributeError if result.code is None. When result.success is False, the code field can be None (as defined in the ConversionResult dataclass), but this line attempts to write it to a file without checking.
if args.output:
output_file = Path(args.output)
if result.code: # Add null check
output_file.write_text(result.code)
print(f"\n✅ Generated SDK program saved to: {output_file}")
else:
print(f"\n⚠️ No code generated to save", file=sys.stderr)| ``` | ||
| 3. **Generate a complete, runnable Python program** that: | ||
| - Imports necessary modules (from auggie_sdk import Agent, dataclasses, typing, etc.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instruction says to import Agent but should say Auggie to match the actual SDK API being used throughout the examples.
- Imports necessary modules (from auggie_sdk import Auggie, dataclasses, typing, etc.)
🤖 Augment PR SummarySummary: Updates the Python SDK examples/docs to match the current Changes:
Technical Notes: The v2 converter includes AST-based syntax/import validation, optional mypy checks, iterative “fix” loops, and optional metadata output alongside the generated script. 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ``` | ||
| 3. **Generate a complete, runnable Python program** that: | ||
| - Imports necessary modules (from auggie_sdk import Agent, dataclasses, typing, etc.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONVERSION_PROMPT tells the model to import/use Agent (and even references Agent()), but the rest of these examples use Auggie and agent.run(), so this prompt is likely to generate non-runnable code.
Other Locations
examples/python-sdk/prompt_to_code.py:112examples/python-sdk/prompt_to_code_v2.py:335
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| """ | ||
| warnings = [] | ||
|
|
||
| # List of allowed imports (common Python stdlib + augment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
augment review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from typing import Optional | ||
|
|
||
| # Add the parent directory to the path so we can import auggie_sdk | ||
| sys.path.insert(0, str(Path(__file__).parent)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.path.insert(0, str(Path(__file__).parent)) doesn’t match the comment (“parent directory”) and won’t help import auggie_sdk unless it’s located in this same folder. This can make the example fragile/inconsistent with the other scripts that add parent.parent (or just rely on pip install auggie-sdk).
Other Locations
examples/python-sdk/prompt_to_code_v2.py:32
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| agent = Auggie( | ||
| workspace_root="/home/augment/augment2", | ||
| model="claude-3-5-sonnet-latest" | ||
| workspace_root=os.getcwd(), # Use current working directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using workspace_root=os.getcwd() makes the effective workspace depend on where the user launches the script; if they run it from examples/python-sdk, prompts like clients/beachhead/src/cli won’t exist relative to the workspace. This can cause the example to fail even when run as documented elsewhere in this folder.
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| The tool generates a complete Python program with: | ||
|
|
||
| 1. **Proper shebang and docstring** | ||
| 2. **All necessary imports** (Agent, dataclasses, typing, etc.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section still refers to Agent (and “Agent initialization”), but the updated examples are based on Auggie; readers may copy/paste the wrong import/class name from here. Consider aligning the terminology with from auggie_sdk import Auggie throughout this new section.
Other Locations
examples/python-sdk/docs/PROMPT_TO_CODE.md:292
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| warnings = [] | ||
|
|
||
| # List of allowed imports (common Python stdlib + augment SDK) | ||
| allowed_imports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update Python SDK examples to match the latest SDK API
This PR modernizes all Python SDK example code to align with the current SDK implementation, ensuring developers have accurate, working examples.
Key Changes
on_agent_message_chunk,on_tool_call,on_tool_response)@operator syntax with explicitagent.run()method calls usingreturn_typeparameterModelNameenum to string literals (e.g.,"sonnet4.5")docs/PROMPT_TO_CODE.mdand added workingprompt_to_code.pyexamplesos.getcwd()andPath.cwd()Impact
Developers using the Python SDK will now have:
🤖 This description was generated automatically. Please react with 👍 if it's helpful or 👎 if it needs improvement.