# Beyond 30 Minutes: Next Steps

> Synthesis of the core model, pointers to deep-dive examples (Middleware, Subagents), and how to contribute to the SDK.

- Repository: google-antigravity/antigravity-sdk-python
- GitHub: https://github.com/google-antigravity/antigravity-sdk-python
- Human wiki: https://grok-wiki.com/public/wiki/google-antigravity-antigravity-sdk-python-2abd361a7867
- Complete Markdown: https://grok-wiki.com/public/wiki/google-antigravity-antigravity-sdk-python-2abd361a7867/llms-full.txt

## Source Files

- `examples/README.md`
- `examples/deep_dives/README.md`
- `CONTRIBUTING.md`
- `examples/getting_started/subagents.py`

---

<details>
<summary>Relevant source files</summary>
The following files were used as context for generating this wiki page:
- [examples/README.md](examples/README.md)
- [examples/deep_dives/README.md](examples/deep_dives/README.md)
- [CONTRIBUTING.md](CONTRIBUTING.md)
- [examples/getting_started/subagents.py](examples/getting_started/subagents.py)
- [examples/getting_started/README.md](examples/getting_started/README.md)
- [examples/deep_dives/agent_middleware.py](examples/deep_dives/agent_middleware.py)
- [google/antigravity/agent.py](google/antigravity/agent.py)
- [google/antigravity/types.py](google/antigravity/types.py)
</details>

# Beyond 30 Minutes: Next Steps

Once you have mastered the [Getting Started](examples/getting_started/README.md) basics, the Google Antigravity SDK provides powerful primitives for scaling agents into production-ready compound systems. This page synthesizes the core architectural model and directs you to advanced implementation patterns for middleware, multi-agent orchestration, and autonomous operations.

Understanding how to compose these layers—from transparent lifecycle hooks to independent subagent delegation—is key to building robust, observable, and efficient AI applications.

## Synthesis of the Core Model

The SDK's architecture is built around the `Agent` and its underlying `Conversation` session. While `agent.chat()` provides a simple entry point, the core model is a declarative system where behavior is shaped by the interaction of tools, policies, and hooks.

### The Agent Lifecycle
An `Agent` instance manages the orchestration of several internal runners. When you enter an `async with Agent(config)` context, the SDK initializes the following components:

| Component | Responsibility |
| :--- | :--- |
| `ToolRunner` | Executes both `BuiltinTools` and custom `PythonTool` functions. |
| `HookRunner` | Intercepts lifecycle events to modify data or control execution flow. |
| `TriggerRunner` | Manages background monitoring and proactive event injection. |
| `McpBridge` | Connects the agent to external toolsets via the Model Context Protocol. |

Sources: [google/antigravity/agent.py:100-165](), [google/antigravity/types.py:212-235]()

## Middleware: Hook-Based Interception

Hooks are the agent equivalent of HTTP middleware or gRPC interceptors. They allow you to inject logic at critical points in the agent's turn without modifying the core reasoning prompt or tool implementations.

### Transparent Pattern: agent_middleware.py
The [agent_middleware.py](examples/deep_dives/agent_middleware.py) example demonstrates how "stacked" hooks create emergent behavior. By chaining multiple hooks, you can implement features that are transparent to the agent:

*   **Rate Limiting**: Use `PreToolCallDecideHook` to enforce per-tool quotas.
*   **Audit Logging**: Use `PostToolCallHook` to record every tool result to a persistent trail.
*   **Error Recovery**: Use `OnToolErrorHook` to intercept exceptions and provide recovery guidance to the model.

```python
# Example of a middleware-style error recovery hook
class FallbackHook(hooks.OnToolErrorHook):
  async def run(self, context, data):
    if isinstance(data, ValueError):
      return "[Could not find user. Use lookup_user instead of display name.]"
    return None
```
Sources: [examples/deep_dives/agent_middleware.py:107-135](), [examples/deep_dives/README.md:15-28]()

## Delegation: Orchestrating Subagents

Subagents allow you to break complex tasks into smaller, scoped contexts. This is a critical pattern for managing token usage and ensuring high-quality reasoning on massive datasets.

### Context Scoping with subagents.py
In [subagents.py](examples/getting_started/subagents.py), a main agent delegates a heavy research task to a subagent. This provides two primary benefits:
1.  **Context Hygiene**: The main agent's context window stays clean; it only receives the subagent's final synthesis, not the raw source documents.
2.  **Specialization**: Subagents can be configured with different tools or policies than the parent agent.

Subagent invocations are tracked via the `START_SUBAGENT` builtin tool, allowing parents to monitor and report on sub-task progress.

Sources: [examples/getting_started/subagents.py:34-45](), [google/antigravity/types.py:231]()

## Deep-Dive Examples Index

For specialized use cases, refer to the following advanced implementation patterns in `examples/deep_dives/`:

*   **[interactive_cli.py](examples/deep_dives/interactive_cli.py)**: Implements "Human-in-the-loop" approval flows using `policy.ask_user`.
*   **[round_based_chat.py](examples/deep_dives/round_based_chat.py)**: Orchestrates synchronized parallel agent discussions using `asyncio.gather`.
*   **[async_chat.py](examples/deep_dives/async_chat.py)**: Demonstrates reactive peer-to-peer agent communication using `asyncio.Condition`.
*   **[doc_maintenance_agent.py](examples/deep_dives/doc_maintenance_agent.py)**: An autonomous agent using `policy.allow` and `policy.deny` for fine-grained file-system scoping.

Sources: [examples/deep_dives/README.md:10-95](), [examples/README.md:35-55]()

## Contributing to the SDK

We are not currently accepting external contributions to the project. However, we encourage the community to report issues or request features through our issue tracker.

*   **Reporting Issues**: File a bug report on the project's tracker.
*   **Community Guidelines**: We follow [Google's Open Source Community Guidelines](https://opensource.google/conduct/).

Sources: [CONTRIBUTING.md:1-12]()

The Google Antigravity SDK is designed to be a modular foundation for compound AI engineering, prioritizing provider-neutrality and local-first execution.
