Add offline mock client to replace Anthropic API dependency#115
Open
gyakusu wants to merge 25 commits intoshareAI-lab:mainfrom
Open
Add offline mock client to replace Anthropic API dependency#115gyakusu wants to merge 25 commits intoshareAI-lab:mainfrom
gyakusu wants to merge 25 commits intoshareAI-lab:mainfrom
Conversation
Create mock_client.py that simulates Anthropic Messages API responses so learners can run `MOCK=1 python agents/s01_agent_loop.py` without an API key or network access. Minimal changes to s01: conditional import based on MOCK env var. https://claude.ai/code/session_01GabR5FftxYc2PcfEuUmWz1
- tests/mock_api.py: stdlib http.server mock for Anthropic Messages API with scripted scenarios matching the s02 demo prompts - tests/run_s02_offline.sh: one-command launcher for offline use - docs/ja/s02-tool-use.md: add offline usage instructions https://claude.ai/code/session_01MkuZcHUYg2cadrXTQj5bEk
- Create tests/mock_client.py with scripted Anthropic API responses that demonstrate TodoManager + nag reminder behaviour - Modify agents/s03_todo_write.py to use MockAnthropic when MOCK=1 - Add tests/test_s03.py with 13 tests covering TodoManager validation, nag reminder logic, and mock scenario integration Run: MOCK=1 python agents/s03_todo_write.py Test: python -m pytest tests/test_s03.py -v https://claude.ai/code/session_018fZRQdSaMZfydDJP16BY1g
Add mock_s05.py that simulates the Anthropic API responses for the two-layer skill injection pattern. Set OFFLINE=1 to run without an API key. Minimal change to s05_skill_loading.py to switch clients. https://claude.ai/code/session_01HuvjsR5RS8DszGQd2Uokv2
Introduce agents/mock_client.py with scripted Anthropic SDK responses so the s06 tutorial runs without an API key (MOCK=1). The mock replays a sequence of read_file tool calls to demonstrate all three compression layers (micro_compact, auto_compact, manual compact). s06_context_compact.py: swap in MockAnthropicClient when MOCK env var is set; soften MODEL_ID to os.getenv with a default. https://claude.ai/code/session_01N84zDvpdNowKwZETvDk8Z7
Enable s08_background_tasks.py to run without an API key by auto-detecting missing credentials (or MOCK=1) and falling back to a pattern-matching mock client that simulates tool_use responses for background task scenarios. https://claude.ai/code/session_01DvgAJyhDY2dgNZSywpH6rT
- tests/mock_server.py: lightweight HTTP server that mimics /v1/messages, returning scripted tool_use responses based on conversation context - agents/s09_agent_teams.py: auto-set dummy ANTHROPIC_API_KEY when ANTHROPIC_BASE_URL is configured (1-line change) - docs/ja/s09-agent-teams.md: add offline usage instructions https://claude.ai/code/session_018WrEioNtZjL1wSxRNrGPXk
- Create agents/mock_server.py: standalone HTTP mock that simulates the Anthropic Messages API with scripted lead/teammate responses - Add --mock flag to s11_autonomous_agents.py for one-command offline use - Mock demonstrates task creation, spawning, auto-claiming, and idle cycles https://claude.ai/code/session_01Mv27P68bcRX7Cj6N8EeA8q
Create mock_s12.py with scripted responses matching the 5-step tutorial flow, and add USE_MOCK=1 flag to s12 for running without API access. https://claude.ai/code/session_01FdznH79o3hX2ktaNwTgAmB
Claude/review ja docs s11 2d77 e
Add offline mock for s12 worktree tutorial
Add offline mock client for s01 agent loop tutorial
add offline mock API server for s02 tutorial
Add offline mock mode for s03 tutorial
feat(s05): add offline mock for skill-loading tutorial
- Create agents/mock_client.py: drop-in MockAnthropic replacement with scripted scenarios (test framework detection, file summarization) - Modify s04_subagent.py to use mock when MOCK=1 env var is set - Run with: MOCK=1 python agents/s04_subagent.py https://claude.ai/code/session_015jMzuncxKNMKW9p61jted4
Add mock Anthropic client for offline s08 tutorial
Add offline mock client for s04 subagent tutorial
Add mock Anthropic API server for offline s09 testing
Merge the s06 context-compact scripted scenario into the existing mock_client.py from the study branch. The unified file supports: - s01-s03: generic pattern-based responses - s04: scenario-based parent/child subagent responses - s06: scripted read_file sequence with summarisation for auto_compact Add MockAnthropicClient alias so both import styles work. https://claude.ai/code/session_01N84zDvpdNowKwZETvDk8Z7
Claude/review ja docs s06 p74a e
- Add s07 task tool scenarios to mock_client.py: supports create-N-tasks with dependency wiring, task board with parallel deps, complete+list, and list tasks patterns. - Update s07_task_system.py to use MOCK=1 pattern consistent with other tutorials (s04, s06). Usage: MOCK=1 python agents/s07_task_system.py https://claude.ai/code/session_0187J4kvcgLJc9DWPWYoJvvS
Add offline mock support for s07 task system tutorial
|
@claude is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
- Replace all Anthropic API imports with `from agents.mock_client import MockAnthropic` - Remove env-var toggling, sys.path hacks, and per-session mock files - Standardize variable naming: `c` → `content` in run_edit, `_safe_path` → `safe_path`, `_run_*` → `run_*` - Standardize output strings: consistent "bytes" and "more" messages - Add `> /dev/` to dangerous commands blocklist in s09/s10/s11 - Delete redundant mock_s05.py, mock_s12.py, mock_server.py - Remove anthropic from requirements.txt https://claude.ai/code/session_01Afh2tutefmEuAEAP4ruGz5
b7aa85c to
215c4cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new
MockAnthropicclient that provides an offline, pattern-based mock implementation of the Anthropic API. All agent scripts now use this mock client instead of requiring actual API credentials and network access.Key Changes
New
agents/mock_client.py: ImplementsMockAnthropicclass withMockMessagesthat mimicsclient.messages.create()behaviorUpdated all agent scripts (s01 through s12, s_full.py):
from anthropic import Anthropicwithfrom agents.mock_client import MockAnthropicload_dotenv()and environment variable setup for API keysclient = Anthropic(...)toclient = MockAnthropic()MODEL = os.environ["MODEL_ID"]toMODEL = "mock"Code cleanup across agent scripts:
_run_bash→run_bash,_safe_path→safe_path)c→content)"> /dev/"to dangerous commands list)Updated
.gitignore: Added.team/directory to ignored pathsUpdated
requirements.txt: Removedanthropic>=0.25.0dependencyImplementation Details
The mock client uses keyword pattern matching to simulate agent behavior:
This enables running and testing the entire agent system offline without API credentials.
https://claude.ai/code/session_01Afh2tutefmEuAEAP4ruGz5