Skip to content

[FEAT] Implement day2-04 ReAct Agent with llama-index on Vertex AI - #31

Merged
ShuN6211 merged 15 commits into
mainfrom
feat/day2-04-react-agent-llama-index
Apr 27, 2026
Merged

[FEAT] Implement day2-04 ReAct Agent with llama-index on Vertex AI#31
ShuN6211 merged 15 commits into
mainfrom
feat/day2-04-react-agent-llama-index

Conversation

@ShuN6211

Copy link
Copy Markdown
Collaborator

Summary

Migrate ReAct Agent tutorial from Anthropic Claude to Vertex AI Gemini using llama-index framework.

Changes

Dependencies

  • ✅ Added llama-index-core>=0.13.0
  • ✅ Added llama-index-llms-gemini>=0.4.0
  • ✅ Added llama-index-embeddings-gemini>=0.2.0

Implementation

  • ✅ Complete notebook.py with 19 cells
    • Section 1: Calculator tools (multiply, add) with ReActAgent
    • Section 2: RAG with QueryEngine tools (Uber/Lyft 10K filings)
  • ✅ Comprehensive README.md with setup, usage, and hands-on tasks
  • ✅ Helper module src/agent.py with tool functions and utilities
  • ✅ Removed plan.md as implementation is complete

Features

  • ReAct Pattern: Thought → Action → Observation cycle
  • Calculator Agent: Solves math problems step-by-step
  • RAG Agent: Answers financial questions from SEC filings
  • Verbose Output: Shows reasoning process
  • System Prompt Inspection: agent.get_prompts() to view internal prompts

Technical Stack

Component Technology
LLM Gemini 2.5 Flash (Vertex AI)
Embeddings Gemini text-embedding-004
Framework llama-index ReActAgent
Tools FunctionTool, QueryEngineTool
Notebook Marimo

Reference

Based on: https://platform.claude.com/cookbook/third-party-llamaindex-react-agent
Adapted for Vertex AI (Anthropic Claude → Google Gemini)

Test Plan

  • Dependencies install successfully with uv sync
  • Notebook syntax is valid (checked with python -m py_compile)
  • Calculator agent executes correctly
  • RAG agent downloads PDFs and builds indexes
  • All cells execute without errors in marimo

Verification

cd day2/04-react-agent
uv sync
uv run marimo edit notebook.py

🤖 Generated with Claude Code

@ShuN6211

Copy link
Copy Markdown
Collaborator Author

ちょっとアレンジできないか考え中

@ShuN6211
ShuN6211 requested review from kittchy and near129 April 24, 2026 06:08
ShuN6211 and others added 3 commits April 27, 2026 16:08
Migrate ReAct Agent tutorial from Anthropic Claude to Vertex AI Gemini
using llama-index framework.

## Changes

- Add llama-index dependencies (core, llms-gemini, embeddings-gemini)
- Implement complete notebook.py with 19 cells:
  - Section 1: Calculator tools (multiply, add) with ReActAgent
  - Section 2: RAG with QueryEngine tools (Uber/Lyft 10K filings)
- Create comprehensive README.md with setup, usage, and hands-on tasks
- Add helper module src/agent.py with tool functions
- Remove plan.md as implementation is complete

## Technical Stack

- LLM: Gemini 2.5 Flash (Vertex AI)
- Embeddings: Gemini text-embedding-004
- Framework: llama-index ReActAgent
- Tools: FunctionTool, QueryEngineTool

## Reference

Based on: https://platform.claude.com/cookbook/third-party-llamaindex-react-agent
Adapted for Vertex AI (Anthropic Claude → Google Gemini)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fix f-string without placeholders (F541)
- Apply ruff format to notebook.py and src/agent.py
- Add trailing commas and fix line lengths

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@ShuN6211
ShuN6211 force-pushed the feat/day2-04-react-agent-llama-index branch from 06a7c5d to 930d3ed Compare April 27, 2026 07:08
ShuN6211 and others added 2 commits April 27, 2026 19:20
The VectorStoreIndex cell had no dependency on the Settings cell,
so marimo could execute it before embed_model was configured,
causing it to fall back to the default OpenAI embeddings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The old llama-index-llms-gemini package uses the deprecated
google.generativeai SDK which causes PERMISSION_DENIED on Vertex AI.
Migrate to llama-index-llms-google-genai and
llama-index-embeddings-google-genai with vertexai_config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@near129 near129 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動けばLGTM!

ShuN6211 and others added 3 commits April 27, 2026 19:39
ReActAgent.from_tools() was removed in llama-index-core 0.14. Use the
new workflow-based API: ReActAgent(tools=..., llm=...) from
llama_index.core.agent.workflow. Agent calls are now async (await
agent.run()) and response is at response.response.content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SimpleDirectoryReader was reading PDFs as raw binary because the PDF
reader dependencies were missing. This caused RAG queries to fail with
"context is unreadable" responses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add PDF parsing explanation (pypdf + llama-index-readers-file)
- Add VectorStoreIndex 3-step process explanation (chunking, embedding, storage)
- Remove Function Calling comparison sections
- Add .gitignore for data/ directory

Changes:
- notebook.py: Add PDF data size info and VectorStoreIndex explanation cells
- README.md: Update learning objectives, remove comparison section
- .gitignore: Exclude data/ directory

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@ShuN6211
ShuN6211 force-pushed the feat/day2-04-react-agent-llama-index branch from 3ee8175 to 96ff411 Compare April 27, 2026 11:41
ShuN6211 and others added 5 commits April 27, 2026 20:55
Changed from showing first 800 characters to full prompt (2041 chars)
to avoid cutting off in the middle of important instructions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed from markdown code blocks to "--- system prompt ---" delimiter
for better readability in the notebook.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use stream_events() to capture and display the ReAct agent's reasoning
process (Thought, Action, Observation) for both calculator and RAG agents.

Changes:
- notebook.py: Collect events and display in markdown with code blocks
- notebook_script.py: Stream events and print to console in real-time
- Set verbose=False (was True) since stream_events provides better output

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Move VectorStoreIndex chunking explanation from explain_chunking.py reference to README.md
- Add comprehensive "VectorStoreIndex のチャンキング詳細" section in README
- Update notebook.py to reference README instead of explain_chunking.py

explain_chunking.py and test_rag.py remain as local development tools (not in git).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…zation

参加者がカスタマイズできるプロダクション品質の ReAct エージェントベースラインを追加

主な機能:
- Tool開発: 新しいツールの追加方法(subtract の例で動作確認済み)
- Prompt Tuning: エージェントの動作・口調変更(カスタムプロンプト例付き)
- LLMパラメータ調整: temperature, model の変更方法

技術スタック:
- 純粋な Python パッケージ(marimo なし)
- main.py エントリポイント(uv run main.py で実行)
- プロダクション品質コード(型ヒント、完全な docstring)
- モジュール化された構造(src/tools.py, src/agent.py)

他の day2 モジュールとの違い:
- notebook.py なし(スクリプト実行のみ)
- 教育的ログなし(クリーンな出力)
- カスタマイズに焦点を当てた設計

04-react-agent の修正:
- black フォーマット適用
- ruff E402 対応(nest_asyncio.apply() の後のインポート)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread day2/04-react-agent/README.md Outdated
Comment thread day2/04-react-agent/README.md Outdated
Comment thread day2/04-react-agent/README.md Outdated
Comment thread day2/07-own_agent/README.md Outdated
Comment thread day2/07-own_agent/README.md Outdated
Comment thread day2/07-own_agent/README.md Outdated
Comment thread day2/07-own_agent/README.md Outdated
ShuN6211 and others added 2 commits April 27, 2026 22:38
day2/04-react-agent/README.md:
- Remove QueryEngineツールの作成 section (Line 147)
- Remove ストリーミングレスポンス task (Line 183)
- Remove メモリ不足 section (Line 310)

day2/07-own_agent/README.md:
- Remove "プロダクション品質" from description (Line 3)
- Simplify temperature descriptions (Line 275, 277)
- Change section title from "エージェントが無限ループする" to "Trouble shoot" (Line 441)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use explicit re-export (as syntax) instead of __all__ to satisfy ruff lint

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@ShuN6211
ShuN6211 merged commit 6de28f6 into main Apr 27, 2026
5 of 7 checks passed
@ShuN6211
ShuN6211 deleted the feat/day2-04-react-agent-llama-index branch April 27, 2026 13:42
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