Skip to content

Conversation

@richhankins
Copy link
Contributor

@richhankins richhankins commented Jan 22, 2026

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

  • Event listener API updates: Renamed event handler methods to match current SDK (on_agent_message_chunk, on_tool_call, on_tool_response)
  • Agent invocation syntax: Replaced @ operator syntax with explicit agent.run() method calls using return_type parameter
  • Type inference behavior: Updated examples to reflect simplified return values (no longer returns tuple with inferred type)
  • Model specification: Changed from ModelName enum to string literals (e.g., "sonnet4.5")
  • Documentation reorganization: Consolidated prompt-to-code documentation into docs/PROMPT_TO_CODE.md and added working prompt_to_code.py examples
  • Path handling: Replaced hardcoded workspace paths with dynamic paths using os.getcwd() and Path.cwd()

Impact

Developers using the Python SDK will now have:

  • Working examples that run without modification
  • Clear patterns for the current API
  • Better organized documentation with cross-references
  • Practical prompt-to-code conversion tools

🤖 This description was generated automatically. Please react with 👍 if it's helpful or 👎 if it needs improvement.

Copy link

@github-actions github-actions bot left a 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",

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:

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)

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.)

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-app-staging
Copy link

augment-app-staging bot commented Jan 22, 2026

🤖 Augment PR Summary

Summary: Updates the Python SDK examples/docs to match the current auggie_sdk APIs and recommended usage patterns.

Changes:

  • Refactors examples away from callable / @-operator patterns to explicit agent.run(...) calls with return_type where needed
  • Updates ACP listener examples to the current callback names (on_agent_message_chunk, on_tool_call, on_tool_response)
  • Removes ModelName enum usage in examples in favor of model string identifiers (e.g., "sonnet4.5")
  • Adjusts example path/workspace handling to avoid hard-coded local paths and instead derive paths from the current environment
  • Reorganizes prompt-to-code docs by moving/consolidating content into examples/python-sdk/docs/PROMPT_TO_CODE.md and updating references
  • Adds two prompt-to-code converter scripts (prompt_to_code.py and prompt_to_code_v2.py) demonstrating single-pass and multi-stage generation workflows

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 👎

Copy link

@augment-app-staging augment-app-staging bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

```
3. **Generate a complete, runnable Python program** that:
- Imports necessary modules (from auggie_sdk import Agent, dataclasses, typing, etc.)

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:112
  • examples/python-sdk/prompt_to_code_v2.py:335

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

"""
warnings = []

# List of allowed imports (common Python stdlib + augment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_imports() doesn’t allow auggie_sdk, so any generated SDK program will produce "Unexpected import" warnings, which then get fed into the fix-iteration prompt and can push the model toward removing required imports.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@richhankins
Copy link
Contributor Author

augment review

Copy link

@augment-app-staging augment-app-staging bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

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))

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

Fix This in Augment

🤖 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

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.

Fix This in Augment

🤖 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.)

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

Fix This in Augment

🤖 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 = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_imports() doesn’t allow __future__, but LLM-generated scripts often include from __future__ import annotations; that will emit warnings and can unnecessarily drive the fix-iteration loop.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@richhankins richhankins merged commit 15542ec into main Jan 22, 2026
@richhankins richhankins deleted the rich-update-examples branch January 22, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants