Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore: add TypedDict related prompt to api/AGENTS.md (#33116)

CoralGarden52c925d17e8f70
diff --git a/api/AGENTS.md b/api/AGENTS.md
index 13adb422764..d43d2528b81 100644
--- a/api/AGENTS.md
+++ b/api/AGENTS.md
@@ -62,6 +62,22 @@ This is the default standard for backend code in this repo. Follow it for new co
- Code should usually include type annotations that match the repo’s current Python version (avoid untyped public APIs and “mystery” values).
- Prefer modern typing forms (e.g. `list[str]`, `dict[str, int]`) and avoid `Any` unless there’s a strong reason.
+- For dictionary-like data with known keys and value types, prefer `TypedDict` over `dict[...]` or `Mapping[...]`.
+- For optional keys in typed payloads, use `NotRequired[...]` (or `total=False` when most fields are optional).
+- Keep `dict[...]` / `Mapping[...]` for truly dynamic key spaces where the key set is unknown.
+
+```python
+from datetime import datetime
+from typing import NotRequired, TypedDict
+
+
+class UserProfile(TypedDict):
+ user_id: str
+ email: str
+ created_at: datetime
+ nickname: NotRequired[str]
+```
+
- For classes, declare member variables at the top of the class body (before `__init__`) so the class shape is obvious at a glance:
```python