Files
agno/cookbook/07_knowledge/09_archive/cloud/github.py
T
Harsh e5651dcc36 fix: cookbooks stale paths left by the directory renumber (#9789)
## Summary

`cookbook/90_tools` and `cookbook/92_models` were renumbered to
`91_tools` and `90_models` by #6042 (2026-01-19), and #6515 (the v2.5
restructure) deleted a set of per-provider examples. Neither pass
updated the references. 296 `cookbook/...` paths across the repo pointed
at directories and files that no longer exist, and nothing in CI checks
path references, so this went unnoticed for seven months.

This resolves every reference that has a live target, removes the
entries whose target no longer exists anywhere, and fixes one case that
was breaking at runtime rather than in docs.

### Runtime fix

`cookbook/frameworks/langgraph/langgraph_session_agentos.py` passed
`app="langgraph_tools_agentos:app"` to `agent_os.serve`. `AgentOS.serve`
hands a string straight to uvicorn, which imports that module — and
`langgraph_tools_agentos` does not exist, so the example could never
start. It now self-references.

### Path fixes

- `cookbook/92_models/...` -> `cookbook/90_models/...`, resolved
folder-locally so a README never points at another provider's file
- pre-restructure flat paths: `cookbook/storage/`, `cookbook/db/`,
`cookbook/agents/`, `cookbook/07_knowledge/cloud|protocol|vector_db/`
- `cookbook/run_pgvector.sh` -> `cookbook/scripts/run_pgvector.sh`;
`./scripts/run_mongodb.sh` -> `./cookbook/scripts/run_mongodb.sh` (7
files)
- self-references in files that moved a directory deeper
(`06_storage/*`, `07_knowledge/09_archive/*`, `frameworks/langgraph/*`,
`91_tools/google/workspace/*`, `91_tools/workspace_tools/*`,
`91_tools/scheduler_tools.py`)
- `storage.py` -> each provider's own `db.py` (renamed per provider;
only `meta/llama_openai` kept the old name)
- renamed successors: `image_agent.py` -> `image_input_url.py`
(anthropic), `image_input.py` (gemini), `image_agent_bytes.py` (watsonx)
- `CONTRIBUTING.md`: four paths that misdirect new contributors, plus
`tools/toolkit/toolkit.py` -> `tools/toolkit.py`
- `08_learning/setup_venv.sh`: `venv_setup.sh` (words transposed) and
`1_user_profile_always.py` -> `1a_user_profile_always.py`

### Removals — target deleted upstream, not renamed

- 8 sections whose script exists nowhere: 6 `async_*` examples folded
into `basic.py` in v3.0, plus `aws/bedrock` storage/knowledge (that
folder has neither file; sibling `aws/claude` does and keeps both
sections)
- 83 `- Streaming on` / `- Streaming off` bullets. Every v3.0 `basic.py`
runs Sync, Sync+Streaming, Async and Async+Streaming in its `__main__`,
so both labels were factually wrong, not only the ones whose file was
deleted.

### Label corrections

- `perplexity` §5 ran `cohere/tool_use.py`; now runs its own
`web_search.py`, bullet relabelled from "DuckDuckGo Search"
- `azure/ai_foundry` ran four `azure/openai/*.py` scripts; now runs its
own
- `litellm` said "DuckDuckGo Search" but the script imports
`YFinanceTools` -> "Financial data"
- `mistral` said "DuckDuckGo search" but the script defines a local
`@tool` -> "Custom tool"

Section numbering is resequenced in every README a removal touched.

## Type of change

- [x] Bug fix
- [ ] New feature
- [ ] Breaking change
- [x] Improvement
- [ ] Model update
- [ ] Other:

---

## Checklist

- [x] Code complies with style guidelines
- [x] Ran format/validation scripts (`./scripts/format.sh` and
`./scripts/validate.sh`)
- [x] Self-review completed
- [x] Documentation updated (comments, docstrings)
- [x] Examples and guides: Relevant cookbook examples have been included
or updated (if applicable)
- [x] Tested in clean environment
- [ ] Tests added/updated (if applicable)

### Duplicate and AI-Generated PR Check

- [x] I have searched existing [open pull requests](../../pulls) and
confirmed that no other PR already addresses this issue
- [x] If a similar PR exists, I have explained below why this PR is a
better approach
- [ ] Check if this PR was entirely AI-generated (by Copilot, Claude
Code, Cursor, etc.)

---

## Additional Notes
2026-08-26 10:34:54 +05:30

102 lines
3.3 KiB
Python

"""
GitHub Content Source for Knowledge
====================================
Load files and folders from GitHub repositories into your Knowledge base,
then query them with an Agent.
Authentication methods:
- Personal Access Token (PAT): simple, set ``token``
- GitHub App: enterprise-grade, set ``app_id``, ``installation_id``, ``private_key``
Requirements:
- PostgreSQL with pgvector: ``./cookbook/scripts/run_pgvector.sh``
- For private repos with PAT: GitHub fine-grained PAT with "Contents: read" permission
- For GitHub App auth: ``pip install PyJWT cryptography``
Run this cookbook:
python cookbook/07_knowledge/09_archive/cloud/github.py
"""
from os import getenv
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.remote_content import GitHubConfig
from agno.models.openai import OpenAIChat
from agno.vectordb.pgvector import PgVector
# ---------------------------------------------------------------------------
# Option 1: Personal Access Token authentication
# ---------------------------------------------------------------------------
# For private repos, set GITHUB_TOKEN env var to a fine-grained PAT with "Contents: read"
github_config = GitHubConfig(
id="my-repo",
name="My Repository",
repo="owner/repo", # Format: owner/repo
token=getenv("GITHUB_TOKEN"), # Optional for public repos
branch="main",
)
# ---------------------------------------------------------------------------
# Option 2: GitHub App authentication
# ---------------------------------------------------------------------------
# For organizations using GitHub Apps instead of personal tokens.
# Requires: pip install PyJWT cryptography
#
# github_config = GitHubConfig(
# id="org-repo",
# name="Org Repository",
# repo="owner/repo",
# app_id=getenv("GITHUB_APP_ID"),
# installation_id=getenv("GITHUB_INSTALLATION_ID"),
# private_key=getenv("GITHUB_APP_PRIVATE_KEY"),
# branch="main",
# )
# ---------------------------------------------------------------------------
# Knowledge Base
# ---------------------------------------------------------------------------
knowledge = Knowledge(
name="GitHub Knowledge",
vector_db=PgVector(
table_name="github_knowledge",
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
),
content_sources=[github_config],
)
# ---------------------------------------------------------------------------
# Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIChat(id="gpt-5.1"),
name="GitHub Agent",
knowledge=knowledge,
search_knowledge=True,
)
# ---------------------------------------------------------------------------
# Run
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# Insert a single file
print("Inserting README from GitHub...")
knowledge.insert(
name="README",
remote_content=github_config.file("README.md"),
)
# Insert an entire folder (recursive)
print("Inserting folder from GitHub...")
knowledge.insert(
name="Docs",
remote_content=github_config.folder("docs"),
)
# Query the knowledge base through the agent
agent.print_response(
"Summarize what this repository is about based on the README",
markdown=True,
)