Skip to content

Commit 66e00db

Browse files
boyangsvlcopybara-github
authored andcommitted
feat: Add async and concurrency guidelines to ADK Style Guide
The new guidelines require all I/O operations to be in async functions, prohibit blocking the event loop, and mandate wrapping synchronous I/O calls with asyncio.to_thread. Co-authored-by: Bo Yang <ybo@google.com> PiperOrigin-RevId: 930825627
1 parent 87538d2 commit 66e00db

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

.agents/skills/adk-style/SKILL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: adk-style
3-
description: ADK development style guide for routine nits — Python idioms, codebase conventions, imports, typing, Pydantic patterns, formatting, logging, and file organization. Use this skill whenever writing code, tests, or reviewing PRs for the ADK project to ensure compliance with styling and coding conventions. Triggers on "code style", "how should I format", "naming convention", "lint", "nit", "imports", "typing", "Pydantic patterns", "testing rules".
3+
description: ADK development style guide for routine nits — Python idioms, codebase conventions, imports, typing, Pydantic patterns, formatting, logging, async/concurrency, and file organization. Use this skill whenever writing code, tests, or reviewing PRs for the ADK project to ensure compliance with styling and coding conventions. Triggers on "code style", "how should I format", "naming convention", "lint", "nit", "imports", "typing", "Pydantic patterns", "testing rules", "async", "io".
44
---
55

66
# ADK Style Guide
@@ -13,6 +13,7 @@ description: ADK development style guide for routine nits — Python idioms, cod
1313
- [Formatting](references/formatting.md) — indentation, line limits, and running pre-commit hooks.
1414
- [Documentation](references/documentation.md) — comments and docstrings.
1515
- [Logging](references/logging.md) — lazy evaluation and log levels.
16+
- [Async and Concurrency](references/async.md) — async I/O requirements, avoiding blocking the event loop.
1617
- [File Organization](references/file-organization.md) — file headers and class organization.
1718

1819
## Testing
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Async and Concurrency Style Guide
2+
3+
- **All I/O operations must be in async functions**: Any operation that
4+
performs I/O (network calls, file system access, database queries, etc.)
5+
must be defined in an `async def` function.
6+
- **Do not block the event loop**: Avoid calling blocking synchronous
7+
functions directly from async code.
8+
- **Wrap synchronous I/O**: If you must use a synchronous library for I/O
9+
(e.g., standard `open()`, `pathlib` file operations, or synchronous
10+
clients), wrap the blocking call in `asyncio.to_thread` to run it in a
11+
separate thread and prevent blocking the main event loop.
12+
13+
Example:
14+
15+
```python
16+
async def save_data(path: Path, data: bytes) -> None:
17+
# Wrap blocking file write in asyncio.to_thread
18+
await asyncio.to_thread(path.write_bytes, data)
19+
```

0 commit comments

Comments
 (0)