Skip to content

Modernize, refine, and standardize the notebook collection - #219

Open
sis0k0 wants to merge 26 commits into
mainfrom
update-agents-notebooks
Open

Modernize, refine, and standardize the notebook collection#219
sis0k0 wants to merge 26 commits into
mainfrom
update-agents-notebooks

Conversation

@sis0k0

@sis0k0 sis0k0 commented Jul 22, 2026

Copy link
Copy Markdown
Member

Overview

This PR is a broad maintenance and quality pass over the notebook collection, focused on notebooks/agents/. It normalizes install commands, cleans up cell outputs, adds "Open in Colab" buttons, standardizes environment-variable handling, migrates notebooks to the current Atlas vector index syntax, fixes dead links, and substantively refines several individual agent notebooks. 35 files changed.

Deeply refined notebooks

Substantive content and narrative rewrites, not just mechanical edits:

Standardized environment-variable handling

The five modernized notebooks now load secrets consistently:

  • Add python-dotenv to the install cell and call load_dotenv() so variables defined in a local .env file are read automatically.
  • Introduce a shared get_or_prompt_env(var_name, prompt_text) helper that returns the value from the environment (.env or already-set) when present, and otherwise falls back to a getpass prompt, raising a clear EnvironmentError if left empty.
  • Keys such as OPENAI_API_KEY, FIREWORKS_API_KEY, and MONGODB_URI are resolved through this helper instead of being hardcoded or prompted ad hoc, so the notebooks run non-interactively when a .env file is present and prompt gracefully when it is not.

Other standardized conventions

Applied consistently across the agent notebooks:

  • Install commands: Replaced !pip with %pip, then normalized all installs to %pip install -U -q for quiet, up-to-date installs.
  • Cell outputs: Cleared noisy pip-install outputs.
  • Open in Colab: Added launch buttons to all notebooks across agents/, rag/, evals/, and partners/.
  • Intro sections: Added consistent titles and problem statements to ~15 agent notebooks.

Modernization

Housekeeping

@sis0k0
sis0k0 requested a review from a team as a code owner July 22, 2026 11:58
@ajosh0504

ajosh0504 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Ran a code review agent on the PR and spot-checked its outputs and recommendations. Seemed sane to me. Here at it's findings: PR-219-review.md

sis0k0 added 8 commits August 19, 2026 09:39
…ll order

ag2 1.0.2 dropped the retrievechat-mongodb extra and the autogen
namespace, so the notebook failed on both %pip install and the
subsequent autogen imports. Pin ag2<1.0 with the openai extra (needed
by autogen.oai.client but not pulled in transitively), and move the
install cell above the dotenv/pymongo/openai imports it was
previously running after.
…niques notebook

SearchIndexModel was migrated to new-style vector field syntax but
never got type="vectorSearch", so Atlas rejects the index creation
with "Attribute mappings missing." The surrounding try/except only
printed the error and let execution continue, masking the failure
until every later $vectorSearch stage broke with no obvious cause.
Now the type is set and the exception propagates instead of being
swallowed.
…sion section

max_tokens=256 left no budget for gpt-oss-20b's reasoning output,
so both agent invocations returned an empty string, the empty answer
got written into MongoDB chat history, and the knowledge_base tool
was never reached in the second turn. Raise max_tokens to 4096 and
fail loudly instead of silently returning '' when a model call comes
back empty.

Also: retitle the "compression retriever" section to describe what
it actually does (compression is exposed as an explicit tool, not a
wrapping retriever) instead of building an unused variable; restore
the gpt2 pin on PromptCompressor so it doesn't fall back to a ~13GB
default model on CPU; drop the unreachable device_map except branch;
correct the prose naming the wrong Fireworks model; pin the
fast-moving langchain packages instead of resolving to latest.

Stale committed outputs from the max_tokens=256 bug (leaked harmony
markers, empty answers) are cleared rather than left in, since they
can't be re-executed without live API credentials in this session.
…ynced docs

MIN_FOREIGN_RESULT_SCORE was set to 0.0, making the score < threshold
check unreachable for any non-negative Tavily score, so every foreign
search result got embedded and written to working_memory regardless
of relevance. Restore the 0.5 threshold.

Also fix markdown/code desync left by an earlier reshuffle: move the
agent demo call and its wrap-up back next to the agent definition,
move the dataset-loading narrative to actually precede the dataset
loading code, remove a verbatim duplicate agent-definition cell, and
restore the missing "Step 3: Data Loading and Preparation" heading
(the notebook was jumping from Step 2 straight to Step 4). Pin
pydantic-ai instead of resolving to latest.
…scaffolding

ANTHROPIC_API_KEY was required via get_or_prompt_env and raised OSError
on an empty prompt, but the notebook actually runs on
ChatOpenAI(model="gpt-5-mini") — ChatAnthropic is commented out. This
blocked anyone without an Anthropic account from getting past that
cell. Drop the requirement and the unused langchain_anthropic install;
fix the invalid commented-out model id (claude-sonnet-4 ->
claude-sonnet-4-0) and note that temperature=0 is silently ignored by
langchain-openai for gpt-5-mini.

Also remove leftover debug scaffolding: a final cell that made an
extra billed LLM call to inspect graph output shape (with its
committed output), and max_retries=1 which made the retry branch
dead code. Pin the fast-moving langchain/langgraph packages instead
of resolving to latest.
A prior dead-link pass mistook pandas' repr ellipsis truncation
(".../access/manage-t...") for a broken link and rewrote it to a URL
that doesn't match its own row label. Revert the committed outputs
back to what the code actually produced rather than keeping the
fabricated substitutions.
- Fix glued H1 headings in 5 notebooks where the heading was appended
  to the Colab badge markdown line with no trailing newline, so it
  rendered as literal text instead of a heading.
- Remove the templated filler problem statement ("This notebook
  solves the problem of building and evaluating <filename> workflows
  using MongoDB-backed retrieval and agent orchestration.") generated
  from the filename in 11 notebooks, rather than leaving generic
  boilerplate in place of a real description.
_search_arxiv created a brand-new arxiv.Client() on every call, so
its built-in "no more than one request every 3 seconds" throttling
was reset each time and never actually applied between calls. Once
the earlier max_tokens fix let the agent make several arXiv searches
within one turn, the back-to-back requests weren't spaced out and
arXiv started returning HTTP 429. Share a single Client instance
across calls so its rate limiting works as intended.
@sis0k0

sis0k0 commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

@ajosh0504 , thank you for the review! I addressed the comments in the latest commits.

@ajosh0504

Copy link
Copy Markdown
Collaborator

@sis0k0 Reran the code review agent. Few more minor issues that result in failures when running the notebook outside of Colab:

  1. Install nest_asyncio inai_agent_with_pydanticai_and_mongodb.ipynb
  2. Install nest_asyncio in agentic_rag_factory_safety_assistant_with_langgraph_langchain_mongodb.ipynb
  3. [Optional] Clean up doubled-flag pip lines in notebooks (Eg: -U -q -U langgraph, -U -q -Uq openai).

Everything else looks good!

sis0k0 added 2 commits August 20, 2026 08:43
Both notebooks call nest_asyncio.apply() but never installed the
package, relying on it being preinstalled in Colab. Add it to the
pip install cell so the notebooks run outside Colab too.
Several install cells had redundant/duplicated flags from a prior
mechanical edit, e.g. "-U -q -U langgraph" and "-U -q -Uq openai".
Dedupe them down to a single -U -q.
@sis0k0

sis0k0 commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

@ajosh0504 , good catch! Cleaned up the doubled install flags and add the missing nest_asyncio installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants