Skip to content

Add automation script to generate mkdocstrings files #1048

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ old_version_tests:

.PHONY: build-docs
build-docs:
uv run docs/scripts/generate_ref_files.py
uv run mkdocs build

.PHONY: build-full-docs
Expand Down
3 changes: 3 additions & 0 deletions docs/ref/computer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Computer`

::: agents.computer
3 changes: 3 additions & 0 deletions docs/ref/extensions/models/litellm_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `LiteLLM Model`

::: agents.extensions.models.litellm_model
3 changes: 3 additions & 0 deletions docs/ref/extensions/models/litellm_provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `LiteLLM Provider`

::: agents.extensions.models.litellm_provider
3 changes: 3 additions & 0 deletions docs/ref/extensions/visualization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Visualization`

::: agents.extensions.visualization
3 changes: 3 additions & 0 deletions docs/ref/logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Logger`

::: agents.logger
3 changes: 3 additions & 0 deletions docs/ref/models/chatcmpl_converter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Chatcmpl Converter`

::: agents.models.chatcmpl_converter
3 changes: 3 additions & 0 deletions docs/ref/models/chatcmpl_helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Chatcmpl Helpers`

::: agents.models.chatcmpl_helpers
3 changes: 3 additions & 0 deletions docs/ref/models/chatcmpl_stream_handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Chatcmpl Stream Handler`

::: agents.models.chatcmpl_stream_handler
3 changes: 3 additions & 0 deletions docs/ref/models/fake_id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Fake Id`

::: agents.models.fake_id
3 changes: 3 additions & 0 deletions docs/ref/models/multi_provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Multi Provider`

::: agents.models.multi_provider
3 changes: 3 additions & 0 deletions docs/ref/models/openai_provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `OpenAI Provider`

::: agents.models.openai_provider
3 changes: 3 additions & 0 deletions docs/ref/prompts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Prompts`

::: agents.prompts
3 changes: 3 additions & 0 deletions docs/ref/strict_schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Strict Schema`

::: agents.strict_schema
3 changes: 3 additions & 0 deletions docs/ref/tool_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Tool Context`

::: agents.tool_context
3 changes: 3 additions & 0 deletions docs/ref/tracing/logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Logger`

::: agents.tracing.logger
3 changes: 3 additions & 0 deletions docs/ref/tracing/provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Provider`

::: agents.tracing.provider
3 changes: 3 additions & 0 deletions docs/ref/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Version`

::: agents.version
3 changes: 3 additions & 0 deletions docs/ref/voice/imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Imports`

::: agents.voice.imports
3 changes: 3 additions & 0 deletions docs/ref/voice/models/openai_model_provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `OpenAI Model Provider`

::: agents.voice.models.openai_model_provider
76 changes: 76 additions & 0 deletions docs/scripts/generate_ref_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python
"""
generate_ref_files.py

Create missing Markdown reference stubs for mkdocstrings.

Usage:
python scripts/generate_ref_files.py
"""

from pathlib import Path
from string import capwords

# ---- Paths -----------------------------------------------------------

REPO_ROOT = Path(__file__).resolve().parent.parent.parent # adjust if layout differs
SRC_ROOT = REPO_ROOT / "src" / "agents" # source tree to scan
DOCS_ROOT = REPO_ROOT / "docs" / "ref" # where stubs go

# ---- Helpers ---------------------------------------------------------


def to_identifier(py_path: Path) -> str:
"""Convert src/agents/foo/bar.py -> 'agents.foo.bar'."""
rel = py_path.relative_to(SRC_ROOT).with_suffix("") # drop '.py'
return ".".join(("agents", *rel.parts))


def md_target(py_path: Path) -> Path:
"""Return docs/ref/.../*.md path corresponding to py_path."""
rel = py_path.relative_to(SRC_ROOT).with_suffix(".md")
return DOCS_ROOT / rel

def pretty_title(last_segment: str) -> str:
"""
Convert a module/file segment like 'tool_context' to 'Tool Context'.
Handles underscores and hyphens; leaves camelCase as‑is except first‑letter cap.
"""
cleaned = last_segment.replace("_", " ").replace("-", " ")
return capwords(cleaned)

# ---- Main ------------------------------------------------------------


def main() -> None:
if not SRC_ROOT.exists():
raise SystemExit(f"Source path not found: {SRC_ROOT}")

created = 0
for py_file in SRC_ROOT.rglob("*.py"):
if py_file.name.startswith("_"): # skip private files
continue
md_path = md_target(py_file)
if md_path.exists():
continue # keep existing
md_path.parent.mkdir(parents=True, exist_ok=True)

identifier = to_identifier(py_file)
title = pretty_title(identifier.split(".")[-1]) # last segment

md_content = f"""# `{title}`

::: {identifier}
"""
md_path.write_text(md_content, encoding="utf-8")
created += 1
print(f"Created {md_path.relative_to(REPO_ROOT)}")

if created == 0:
print("All reference files were already present.")
else:
print(f"Done. {created} new file(s) created.")


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ plugins:
- ref/memory.md
- ref/repl.md
- ref/tool.md
- ref/tool_context.md
- ref/result.md
- ref/stream_events.md
- ref/handoffs.md
Expand Down