botrun-flow-lang 5.12.264__tar.gz → 6.2.61__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/CHANGELOG.md +20 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/PKG-INFO +5 -6
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/langgraph_api.py +8 -3
- botrun_flow_lang-6.2.61/botrun_flow_lang/api/langgraph_constants.py +11 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/langgraph_react_agent.py +17 -11
- botrun_flow_lang-6.2.61/botrun_flow_lang/langgraph_agents/agents/util/custom_vertex_claude.py +406 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/img_util.py +58 -16
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/pdf_analyzer.py +112 -36
- botrun_flow_lang-6.2.61/botrun_flow_lang/langgraph_agents/agents/util/usage_metadata.py +34 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/mcp_server/default_mcp.py +152 -42
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/pyproject.toml +6 -6
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/uv.lock +3023 -3090
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/.env_template +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/.gcloudignore +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/.gitignore +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/.vscode/launch.json +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/CLAUDE.md +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/Dockerfile.template +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/README.md +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/auth_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/auth_utils.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/botrun_back_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/flow_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/hatch_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/line_bot_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/model_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/rate_limit_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/routes.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/search_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/storage_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/subsidy_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/subsidy_api_system_prompt.txt +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/user_setting_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/version_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/api/youtube_api.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/constants.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/agent_runner.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/agent_tools/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/agent_tools/step_planner.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/checkpointer/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/checkpointer/firestore_checkpointer.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/gov_researcher/GOV_RESEARCHER_PRD.md +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/gov_researcher/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/gov_researcher/gemini_subsidy_graph.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/gov_researcher/gov_researcher_2_graph.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/gov_researcher/gov_researcher_graph.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/search_agent_graph.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/tools/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/tools/gemini_code_execution.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/gemini_grounding.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/html_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/local_files.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/mermaid_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/model_utils.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/pdf_cache.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/pdf_processor.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/perplexity_search.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/plotly_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/tavily_search.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/agents/util/youtube_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/cache/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/langgraph_agents/cache/langgraph_botrun_cache.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/llm_agent/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/llm_agent/llm_agent.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/llm_agent/llm_agent_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/log/.gitignore +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/main.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/main_fast.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/mcp_server/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/models/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/models/nodes/utils.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/models/token_usage.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/requirements.txt +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/base/firestore_base.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/hatch/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/hatch/hatch_factory.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/hatch/hatch_fs_store.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/storage/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/storage/storage_cs_store.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/storage/storage_factory.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/storage/storage_store.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/user_setting/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/user_setting/user_setting_factory.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/services/user_setting/user_setting_fs_store.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/static/docs/tools/index.html +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/api_functional_tests.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/api_stress_test.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/shared_hatch_tests.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_botrun_app.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/(/346/272/253/351/246/250/346/210/220/346/236/234 /350/241/214/346/224/277/350/253/213/347/244/272/345/214/257/347/270/275)20250210/345/220/221 /344/270/212/344/272/272/345/240/261/345/221/212/347/260/241/345/240/261 (1).pdf" +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/11206_10808/344/272/272/345/217/243/346/225/270(3/346/256/265/345/271/264/351/275/241/347/265/204+/346/257/224/347/216/207)/345/244/251/344/270/213/351/233/234/350/252/2141.pdf" +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/1120701A/346/265/267/345/273/243/351/233/242/345/262/270/351/242/250/345/212/233/347/231/274/351/233/273/350/250/210/347/225/253/347/222/260/345/242/203/345/275/261/351/237/277/350/252/252/346/230/216/346/233/270-C04.PDF" +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/ImportedPhoto.760363950.029251.jpeg +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/ImportedPhoto.760363950.030446.jpeg +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/ImportedPhoto.760363950.031127.jpeg +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/d5712343.jpg +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/spot_difference_1.png +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_files/spot_difference_2.png +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_html_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_img_analyzer.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_img_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_local_files.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_mermaid_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_pdf_analyzer.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_plotly_util.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tests/test_run_workflow_engine.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tools/generate_docs.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/tools/templates/tools.html +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/botrun_logger.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/clients/__init__.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/clients/rate_limit_client.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/clients/token_verify_client.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/google_drive_utils.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/langchain_utils.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/botrun_flow_lang/utils/yaml_utils.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/cloudbuild_template.yaml +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/convert_newlines.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/deploy.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/langgraph.json +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/poetry.lock +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/poetry.toml +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/requirements.txt +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/requirements_fast.txt +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_bigline.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_dev.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_evaldev.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_fast.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_modaline.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_prod.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/deploy_sebaline.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/firestore_checkpointer_delete_thread.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/generate_docs.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/llm_time_test.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/run_langgraph.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/run_langgraph_react.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/run_youtube_summary.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/scrape_pdf.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/seba_pypi.sh +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/sh/subsidy_test.py +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search/agent-architecture-upgrade.excalidraw +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search/line_dev.excalidraw +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search/subsidy_agent.excalidraw +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search/subsidy_agent_dev.excalidraw +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search/temp_txt.md +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search/temp_txt2.md +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/gov-search//346/264/245/350/262/274line/345/276/205/350/250/216/350/253/226.excalidraw" +0 -0
- {botrun_flow_lang-5.12.264 → botrun_flow_lang-6.2.61}/specs/system_thinking.excalidraw +0 -0
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [6.2.61]
|
|
2
|
+
- 新增 `ChatVertexAIClaude` 自製 LangGraph chat model(`custom_vertex_claude.py`):
|
|
3
|
+
- 透過 Vertex AI `rawPredict` REST API 直接呼叫 Claude,取代 `ChatAnthropicVertex`
|
|
4
|
+
- 支援 tool calling,完整相容 LangGraph react agent
|
|
5
|
+
- 處理 SystemMessage(含 cache_control)、HumanMessage、AIMessage(含 tool_calls)、ToolMessage 轉換
|
|
6
|
+
- 自動合併連續同角色訊息(Anthropic API 要求)
|
|
7
|
+
- 移除 `langchain-google-vertexai` 依賴,避免載入 `google-cloud-aiplatform`(約 26 秒),加速啟動
|
|
8
|
+
|
|
9
|
+
## [6.1.261]
|
|
10
|
+
- 優化 MCP 工具 docstring,避免 LLM 混淆 URL 有效期限:
|
|
11
|
+
- `create_html_page`:明確標示為 PERMANENT URL that never expires
|
|
12
|
+
- `generate_tmp_public_url`:改為 temporary URL that may be deleted periodically
|
|
13
|
+
|
|
14
|
+
## [6.1.72]
|
|
15
|
+
- web_search 如果沒有使用 openrouter 的 api 時,回傳的 usage_metadata model 要加入 perplexity/ 前綴
|
|
16
|
+
|
|
17
|
+
## [6.1.71]
|
|
18
|
+
- 幾個 mcp 工具加入回傳 llm usage_metadata
|
|
19
|
+
- web_search、chat_with_pdf、chat_with_imgs、generate_image
|
|
20
|
+
|
|
1
21
|
## [5.12.264]
|
|
2
22
|
- 修正 botrun_flow_lang/langgraph_agents/agents/langgraph_react_agent.py
|
|
3
23
|
- from langchain.tools import StructuredTool 改成 from langchain_core.tools import StructuredTool
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: botrun-flow-lang
|
|
3
|
-
Version:
|
|
3
|
+
Version: 6.2.61
|
|
4
4
|
Summary: A flow language for botrun
|
|
5
5
|
Author-email: sebastian-hsu <sebastian.hsu@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -27,12 +27,11 @@ Requires-Dist: google-cloud-storage<3,>=2.18
|
|
|
27
27
|
Requires-Dist: google-genai>=1.28.0
|
|
28
28
|
Requires-Dist: jinja2>=3.1.6
|
|
29
29
|
Requires-Dist: langchain-anthropic>=0.3.10
|
|
30
|
-
Requires-Dist: langchain-aws>=0.
|
|
30
|
+
Requires-Dist: langchain-aws>=1.0.0
|
|
31
31
|
Requires-Dist: langchain-community>=0.3.27
|
|
32
|
-
Requires-Dist: langchain-core>=
|
|
32
|
+
Requires-Dist: langchain-core>=1.1.2
|
|
33
33
|
Requires-Dist: langchain-google-community>=2.0.3
|
|
34
|
-
Requires-Dist: langchain-google-genai>=
|
|
35
|
-
Requires-Dist: langchain-google-vertexai<3.0.0,>=2.1.2
|
|
34
|
+
Requires-Dist: langchain-google-genai>=4.0.0
|
|
36
35
|
Requires-Dist: langchain-mcp-adapters>=0.1.7
|
|
37
36
|
Requires-Dist: langchain-openai>=0.3.28
|
|
38
37
|
Requires-Dist: langchain>=0.3.27
|
|
@@ -41,7 +40,7 @@ Requires-Dist: langgraph-supervisor>=0.0.20
|
|
|
41
40
|
Requires-Dist: langgraph>=0.6.3
|
|
42
41
|
Requires-Dist: line-bot-sdk>=3.17.1
|
|
43
42
|
Requires-Dist: mcp<1.11.0,>=1.10.1
|
|
44
|
-
Requires-Dist: numpy
|
|
43
|
+
Requires-Dist: numpy>=1.24.0
|
|
45
44
|
Requires-Dist: openai>=1.99.1
|
|
46
45
|
Requires-Dist: pandas>=2.2.3
|
|
47
46
|
Requires-Dist: pdfminer-six==20250506
|
|
@@ -113,12 +113,17 @@ class GraphSchemaRequest(BaseModel):
|
|
|
113
113
|
graph_name: str
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
# 從常數檔案匯入,避免外部模組為了取得常數而觸發重型 import
|
|
117
|
+
from botrun_flow_lang.api.langgraph_constants import (
|
|
118
|
+
LANGGRAPH_REACT_AGENT,
|
|
119
|
+
GOV_SUBSIDY_AGENT,
|
|
120
|
+
PERPLEXITY_SEARCH_AGENT,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# 僅在此檔案內部使用的常數
|
|
117
124
|
CUSTOM_WEB_RESEARCH_AGENT = "custom_web_research_agent"
|
|
118
|
-
LANGGRAPH_REACT_AGENT = "langgraph_react_agent"
|
|
119
125
|
DEEP_RESEARCH_AGENT = "deep_research_agent"
|
|
120
126
|
# GOV_RESEARCHER_AGENT = "gov_researcher_agent"
|
|
121
|
-
GOV_SUBSIDY_AGENT = "gov_subsidy_agent"
|
|
122
127
|
GEMINI_SUBSIDY_AGENT = "gemini_subsidy_agent"
|
|
123
128
|
|
|
124
129
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LangGraph 常數定義
|
|
3
|
+
|
|
4
|
+
此檔案只包含常數定義,不包含任何會觸發重型 SDK 載入的 import。
|
|
5
|
+
這樣可以讓其他模組在只需要常數時,不會觸發 langchain_google_vertexai 等重型套件的載入。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# Graph 名稱常數
|
|
9
|
+
LANGGRAPH_REACT_AGENT = "langgraph_react_agent"
|
|
10
|
+
GOV_SUBSIDY_AGENT = "gov_subsidy_agent"
|
|
11
|
+
PERPLEXITY_SEARCH_AGENT = "perplexity_search_agent"
|
|
@@ -86,8 +86,11 @@ from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
|
86
86
|
# ========
|
|
87
87
|
# for Vertex AI
|
|
88
88
|
from google.oauth2 import service_account
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
# 使用自製的 ChatVertexAIClaude 取代 ChatAnthropicVertex,
|
|
90
|
+
# 透過 rawPredict REST API 直接呼叫 Claude,避免載入 google-cloud-aiplatform(約 26 秒)
|
|
91
|
+
from botrun_flow_lang.langgraph_agents.agents.util.custom_vertex_claude import (
|
|
92
|
+
ChatVertexAIClaude,
|
|
93
|
+
)
|
|
91
94
|
|
|
92
95
|
load_dotenv()
|
|
93
96
|
|
|
@@ -234,8 +237,10 @@ def get_react_agent_model(model_name: str = ""):
|
|
|
234
237
|
# 判斷模型類型並創建相應實例
|
|
235
238
|
if vertex_model_name.startswith("gemini-"):
|
|
236
239
|
# Gemini 系列:gemini-2.5-pro, gemini-2.5-flash, gemini-pro
|
|
237
|
-
|
|
240
|
+
# 使用 ChatGoogleGenerativeAI + vertexai=True,避免載入重型的 langchain_google_vertexai
|
|
241
|
+
model = ChatGoogleGenerativeAI(
|
|
238
242
|
model=vertex_model_name,
|
|
243
|
+
vertexai=True,
|
|
239
244
|
location=vertex_region,
|
|
240
245
|
project=vertex_project,
|
|
241
246
|
credentials=credentials,
|
|
@@ -243,21 +248,22 @@ def get_react_agent_model(model_name: str = ""):
|
|
|
243
248
|
max_tokens=GEMINI_MAX_TOKENS,
|
|
244
249
|
)
|
|
245
250
|
logger.info(
|
|
246
|
-
f"model
|
|
251
|
+
f"model ChatGoogleGenerativeAI(vertexai=True) {vertex_model_name} @ {vertex_region} (project: {vertex_project})"
|
|
247
252
|
)
|
|
248
253
|
|
|
249
254
|
elif "claude" in vertex_model_name.lower() or vertex_model_name.startswith("maison/"):
|
|
250
255
|
# Anthropic Claude (model garden)
|
|
251
|
-
|
|
256
|
+
# 使用自製的 ChatVertexAIClaude,避免載入 google-cloud-aiplatform
|
|
257
|
+
model = ChatVertexAIClaude(
|
|
252
258
|
model=vertex_model_name,
|
|
253
259
|
location=vertex_region,
|
|
254
|
-
|
|
260
|
+
project_id=vertex_project,
|
|
255
261
|
credentials=credentials,
|
|
256
262
|
temperature=0,
|
|
257
263
|
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
258
264
|
)
|
|
259
265
|
logger.info(
|
|
260
|
-
f"model
|
|
266
|
+
f"model ChatVertexAIClaude {vertex_model_name} @ {vertex_region} (project: {vertex_project})"
|
|
261
267
|
)
|
|
262
268
|
|
|
263
269
|
else:
|
|
@@ -301,9 +307,9 @@ def get_react_agent_model(model_name: str = ""):
|
|
|
301
307
|
"VERTEX_AI_GOOGLE_APPLICATION_CREDENTIALS not set or file not found. Using ADC if available."
|
|
302
308
|
)
|
|
303
309
|
|
|
304
|
-
#
|
|
305
|
-
model =
|
|
306
|
-
|
|
310
|
+
# 使用自製的 ChatVertexAIClaude,避免載入 google-cloud-aiplatform
|
|
311
|
+
model = ChatVertexAIClaude(
|
|
312
|
+
project_id=vertex_project,
|
|
307
313
|
model=vertex_model,
|
|
308
314
|
location=vertex_location,
|
|
309
315
|
credentials=credentials,
|
|
@@ -311,7 +317,7 @@ def get_react_agent_model(model_name: str = ""):
|
|
|
311
317
|
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
312
318
|
)
|
|
313
319
|
logger.info(
|
|
314
|
-
f"model
|
|
320
|
+
f"model ChatVertexAIClaude {vertex_project} @ {vertex_model} @ {vertex_location}"
|
|
315
321
|
)
|
|
316
322
|
|
|
317
323
|
else:
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom Vertex AI Claude chat model for LangGraph.
|
|
3
|
+
|
|
4
|
+
Lightweight BaseChatModel that calls Claude via Vertex AI's rawPredict REST API,
|
|
5
|
+
avoiding the heavy google-cloud-aiplatform dependency (~26s import time).
|
|
6
|
+
|
|
7
|
+
Supports tool calling for LangGraph react agent compatibility.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
from google.auth.transport.requests import Request
|
|
16
|
+
from google.oauth2 import service_account
|
|
17
|
+
from langchain_core.callbacks import CallbackManagerForLLMRun
|
|
18
|
+
from langchain_core.language_models.chat_models import BaseChatModel
|
|
19
|
+
from langchain_core.messages import (
|
|
20
|
+
AIMessage,
|
|
21
|
+
BaseMessage,
|
|
22
|
+
HumanMessage,
|
|
23
|
+
SystemMessage,
|
|
24
|
+
ToolMessage,
|
|
25
|
+
)
|
|
26
|
+
from langchain_core.outputs import ChatGeneration, ChatResult
|
|
27
|
+
from pydantic import ConfigDict
|
|
28
|
+
|
|
29
|
+
from botrun_flow_lang.utils.botrun_logger import get_default_botrun_logger
|
|
30
|
+
|
|
31
|
+
logger = get_default_botrun_logger()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ChatVertexAIClaude(BaseChatModel):
|
|
35
|
+
"""
|
|
36
|
+
Lightweight Vertex AI Claude chat model using rawPredict REST API.
|
|
37
|
+
|
|
38
|
+
Replaces ChatAnthropicVertex without importing google-cloud-aiplatform.
|
|
39
|
+
Supports tool calling for LangGraph react agent.
|
|
40
|
+
|
|
41
|
+
Usage:
|
|
42
|
+
model = ChatVertexAIClaude(
|
|
43
|
+
model="claude-sonnet-4-5-20250929",
|
|
44
|
+
project_id="my-project",
|
|
45
|
+
location="asia-east1",
|
|
46
|
+
credentials=my_credentials, # or service_account_file="path/to/sa.json"
|
|
47
|
+
)
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
model: str = "claude-sonnet-4-5-20250929"
|
|
51
|
+
max_tokens: int = 64000
|
|
52
|
+
temperature: float = 0
|
|
53
|
+
project_id: str = ""
|
|
54
|
+
location: str = "asia-east1"
|
|
55
|
+
credentials: Any = None
|
|
56
|
+
service_account_file: str = ""
|
|
57
|
+
|
|
58
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def _llm_type(self) -> str:
|
|
62
|
+
return "vertex-ai-claude-custom"
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def _identifying_params(self) -> Dict[str, Any]:
|
|
66
|
+
return {
|
|
67
|
+
"model": self.model,
|
|
68
|
+
"max_tokens": self.max_tokens,
|
|
69
|
+
"temperature": self.temperature,
|
|
70
|
+
"project_id": self.project_id,
|
|
71
|
+
"location": self.location,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def bind_tools(
|
|
75
|
+
self,
|
|
76
|
+
tools: List[Any],
|
|
77
|
+
*,
|
|
78
|
+
tool_choice: Optional[Union[str, Dict]] = None,
|
|
79
|
+
**kwargs,
|
|
80
|
+
):
|
|
81
|
+
"""Convert tools to Anthropic format and bind via Runnable.bind()."""
|
|
82
|
+
formatted_tools = _convert_tools_to_anthropic(tools)
|
|
83
|
+
bind_kwargs: Dict[str, Any] = {"tools": formatted_tools, **kwargs}
|
|
84
|
+
if tool_choice is not None:
|
|
85
|
+
bind_kwargs["tool_choice"] = tool_choice
|
|
86
|
+
return self.bind(**bind_kwargs)
|
|
87
|
+
|
|
88
|
+
def _get_access_token(self) -> str:
|
|
89
|
+
"""Get OAuth2 access token for Vertex AI API."""
|
|
90
|
+
if self.credentials:
|
|
91
|
+
creds = self.credentials
|
|
92
|
+
elif self.service_account_file:
|
|
93
|
+
creds = service_account.Credentials.from_service_account_file(
|
|
94
|
+
self.service_account_file,
|
|
95
|
+
scopes=["https://www.googleapis.com/auth/cloud-platform"],
|
|
96
|
+
)
|
|
97
|
+
else:
|
|
98
|
+
raise ValueError(
|
|
99
|
+
"ChatVertexAIClaude requires either 'credentials' or 'service_account_file'"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if not creds.valid or creds.expired:
|
|
103
|
+
creds.refresh(Request())
|
|
104
|
+
return creds.token
|
|
105
|
+
|
|
106
|
+
def _convert_messages(
|
|
107
|
+
self, messages: List[BaseMessage]
|
|
108
|
+
) -> Tuple[Union[str, List[Dict]], List[Dict]]:
|
|
109
|
+
"""Convert LangChain messages to Anthropic API format.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
(system, api_messages) tuple.
|
|
113
|
+
system: str or list of content blocks (preserves cache_control).
|
|
114
|
+
api_messages: list of Anthropic-format message dicts.
|
|
115
|
+
"""
|
|
116
|
+
system_blocks: List[Any] = []
|
|
117
|
+
raw_messages: List[Dict] = []
|
|
118
|
+
|
|
119
|
+
for msg in messages:
|
|
120
|
+
if isinstance(msg, SystemMessage):
|
|
121
|
+
if isinstance(msg.content, str):
|
|
122
|
+
system_blocks.append({"type": "text", "text": msg.content})
|
|
123
|
+
elif isinstance(msg.content, list):
|
|
124
|
+
for block in msg.content:
|
|
125
|
+
if isinstance(block, dict):
|
|
126
|
+
system_blocks.append(block)
|
|
127
|
+
elif isinstance(block, str):
|
|
128
|
+
system_blocks.append({"type": "text", "text": block})
|
|
129
|
+
|
|
130
|
+
elif isinstance(msg, HumanMessage):
|
|
131
|
+
raw_messages.append({"role": "user", "content": msg.content})
|
|
132
|
+
|
|
133
|
+
elif isinstance(msg, AIMessage):
|
|
134
|
+
content_blocks = []
|
|
135
|
+
if msg.content:
|
|
136
|
+
if isinstance(msg.content, str):
|
|
137
|
+
content_blocks.append(
|
|
138
|
+
{"type": "text", "text": msg.content}
|
|
139
|
+
)
|
|
140
|
+
elif isinstance(msg.content, list):
|
|
141
|
+
for block in msg.content:
|
|
142
|
+
if isinstance(block, str):
|
|
143
|
+
content_blocks.append(
|
|
144
|
+
{"type": "text", "text": block}
|
|
145
|
+
)
|
|
146
|
+
elif isinstance(block, dict):
|
|
147
|
+
content_blocks.append(block)
|
|
148
|
+
for tc in msg.tool_calls or []:
|
|
149
|
+
content_blocks.append(
|
|
150
|
+
{
|
|
151
|
+
"type": "tool_use",
|
|
152
|
+
"id": tc["id"],
|
|
153
|
+
"name": tc["name"],
|
|
154
|
+
"input": tc["args"],
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
raw_messages.append(
|
|
158
|
+
{
|
|
159
|
+
"role": "assistant",
|
|
160
|
+
"content": content_blocks if content_blocks else "",
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
elif isinstance(msg, ToolMessage):
|
|
165
|
+
tool_content = msg.content
|
|
166
|
+
if not isinstance(tool_content, str):
|
|
167
|
+
tool_content = json.dumps(tool_content, ensure_ascii=False)
|
|
168
|
+
raw_messages.append(
|
|
169
|
+
{
|
|
170
|
+
"role": "user",
|
|
171
|
+
"content": [
|
|
172
|
+
{
|
|
173
|
+
"type": "tool_result",
|
|
174
|
+
"tool_use_id": msg.tool_call_id,
|
|
175
|
+
"content": tool_content,
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
merged = _merge_consecutive_messages(raw_messages)
|
|
182
|
+
|
|
183
|
+
# Return system as string (simple) or list (structured with cache_control)
|
|
184
|
+
has_cache_control = any(
|
|
185
|
+
isinstance(b, dict) and "cache_control" in b for b in system_blocks
|
|
186
|
+
)
|
|
187
|
+
if len(system_blocks) == 1 and not has_cache_control:
|
|
188
|
+
system: Union[str, List[Dict]] = system_blocks[0].get("text", "")
|
|
189
|
+
elif system_blocks:
|
|
190
|
+
system = system_blocks
|
|
191
|
+
else:
|
|
192
|
+
system = ""
|
|
193
|
+
|
|
194
|
+
return system, merged
|
|
195
|
+
|
|
196
|
+
def _generate(
|
|
197
|
+
self,
|
|
198
|
+
messages: List[BaseMessage],
|
|
199
|
+
stop: Optional[List[str]] = None,
|
|
200
|
+
run_manager: Optional[CallbackManagerForLLMRun] = None,
|
|
201
|
+
**kwargs,
|
|
202
|
+
) -> ChatResult:
|
|
203
|
+
"""Call Vertex AI Claude via rawPredict (non-streaming)."""
|
|
204
|
+
system, api_messages = self._convert_messages(messages)
|
|
205
|
+
access_token = self._get_access_token()
|
|
206
|
+
|
|
207
|
+
url = (
|
|
208
|
+
f"https://{self.location}-aiplatform.googleapis.com/v1/"
|
|
209
|
+
f"projects/{self.project_id}/locations/{self.location}/"
|
|
210
|
+
f"publishers/anthropic/models/{self.model}:rawPredict"
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
payload: Dict[str, Any] = {
|
|
214
|
+
"anthropic_version": "vertex-2023-10-16",
|
|
215
|
+
"messages": api_messages,
|
|
216
|
+
"max_tokens": self.max_tokens,
|
|
217
|
+
"temperature": self.temperature,
|
|
218
|
+
}
|
|
219
|
+
if system:
|
|
220
|
+
payload["system"] = system
|
|
221
|
+
if stop:
|
|
222
|
+
payload["stop_sequences"] = stop
|
|
223
|
+
|
|
224
|
+
# Tools from bind_tools()
|
|
225
|
+
tools = kwargs.get("tools", [])
|
|
226
|
+
if tools:
|
|
227
|
+
payload["tools"] = tools
|
|
228
|
+
|
|
229
|
+
# Tool choice
|
|
230
|
+
tool_choice = kwargs.get("tool_choice")
|
|
231
|
+
if tool_choice:
|
|
232
|
+
if isinstance(tool_choice, str):
|
|
233
|
+
if tool_choice == "auto":
|
|
234
|
+
payload["tool_choice"] = {"type": "auto"}
|
|
235
|
+
elif tool_choice == "any":
|
|
236
|
+
payload["tool_choice"] = {"type": "any"}
|
|
237
|
+
elif tool_choice == "none":
|
|
238
|
+
payload.pop("tools", None)
|
|
239
|
+
else:
|
|
240
|
+
payload["tool_choice"] = {
|
|
241
|
+
"type": "tool",
|
|
242
|
+
"name": tool_choice,
|
|
243
|
+
}
|
|
244
|
+
elif isinstance(tool_choice, dict):
|
|
245
|
+
payload["tool_choice"] = tool_choice
|
|
246
|
+
|
|
247
|
+
logger.info(
|
|
248
|
+
f"[ChatVertexAIClaude] rawPredict: model={self.model}, "
|
|
249
|
+
f"location={self.location}, messages={len(api_messages)}, "
|
|
250
|
+
f"tools={len(tools)}"
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
# Make API call via httpx
|
|
254
|
+
data = _http_post_json(url, payload, access_token)
|
|
255
|
+
|
|
256
|
+
# Parse response
|
|
257
|
+
text_parts = []
|
|
258
|
+
tool_calls = []
|
|
259
|
+
for block in data.get("content", []):
|
|
260
|
+
block_type = block.get("type", "")
|
|
261
|
+
if block_type == "text":
|
|
262
|
+
text_parts.append(block.get("text", ""))
|
|
263
|
+
elif block_type == "tool_use":
|
|
264
|
+
tool_calls.append(
|
|
265
|
+
{
|
|
266
|
+
"id": block["id"],
|
|
267
|
+
"name": block["name"],
|
|
268
|
+
"args": block.get("input", {}),
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
usage = data.get("usage", {})
|
|
273
|
+
input_tokens = usage.get("input_tokens", 0)
|
|
274
|
+
output_tokens = usage.get("output_tokens", 0)
|
|
275
|
+
|
|
276
|
+
ai_message = AIMessage(
|
|
277
|
+
content="".join(text_parts),
|
|
278
|
+
tool_calls=tool_calls,
|
|
279
|
+
usage_metadata={
|
|
280
|
+
"input_tokens": input_tokens,
|
|
281
|
+
"output_tokens": output_tokens,
|
|
282
|
+
"total_tokens": input_tokens + output_tokens,
|
|
283
|
+
},
|
|
284
|
+
response_metadata={
|
|
285
|
+
"model": self.model,
|
|
286
|
+
"stop_reason": data.get("stop_reason", ""),
|
|
287
|
+
},
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
logger.info(
|
|
291
|
+
f"[ChatVertexAIClaude] Response: "
|
|
292
|
+
f"text_len={len(ai_message.content)}, "
|
|
293
|
+
f"tool_calls={len(tool_calls)}, "
|
|
294
|
+
f"tokens=({input_tokens}+{output_tokens}={input_tokens + output_tokens})"
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
return ChatResult(
|
|
298
|
+
generations=[ChatGeneration(message=ai_message)],
|
|
299
|
+
llm_output={
|
|
300
|
+
"model": self.model,
|
|
301
|
+
"usage": {
|
|
302
|
+
"input_tokens": input_tokens,
|
|
303
|
+
"output_tokens": output_tokens,
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _http_post_json(
|
|
310
|
+
url: str, payload: Dict[str, Any], access_token: str
|
|
311
|
+
) -> Dict[str, Any]:
|
|
312
|
+
"""POST JSON to URL with Bearer auth. Returns parsed JSON response."""
|
|
313
|
+
headers = {
|
|
314
|
+
"Content-Type": "application/json",
|
|
315
|
+
"Authorization": f"Bearer {access_token}",
|
|
316
|
+
}
|
|
317
|
+
try:
|
|
318
|
+
with httpx.Client(timeout=300.0) as client:
|
|
319
|
+
response = client.post(url, headers=headers, json=payload)
|
|
320
|
+
if response.status_code != 200:
|
|
321
|
+
error_msg = (
|
|
322
|
+
f"Vertex AI API error: {response.status_code} - {response.text}"
|
|
323
|
+
)
|
|
324
|
+
logger.error(f"[ChatVertexAIClaude] {error_msg}")
|
|
325
|
+
raise Exception(error_msg)
|
|
326
|
+
return response.json()
|
|
327
|
+
except httpx.HTTPStatusError as e:
|
|
328
|
+
error_body = e.response.text if e.response else ""
|
|
329
|
+
error_msg = f"Vertex AI API error: {e.response.status_code} - {error_body}"
|
|
330
|
+
logger.error(f"[ChatVertexAIClaude] {error_msg}")
|
|
331
|
+
raise Exception(error_msg) from e
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def _convert_tools_to_anthropic(tools: List[Any]) -> List[Dict]:
|
|
335
|
+
"""Convert LangChain tools to Anthropic tool format."""
|
|
336
|
+
from langchain_core.utils.function_calling import convert_to_openai_tool
|
|
337
|
+
|
|
338
|
+
anthropic_tools = []
|
|
339
|
+
for tool in tools:
|
|
340
|
+
if isinstance(tool, dict):
|
|
341
|
+
if "input_schema" in tool:
|
|
342
|
+
anthropic_tools.append(tool)
|
|
343
|
+
elif "function" in tool:
|
|
344
|
+
func = tool["function"]
|
|
345
|
+
anthropic_tools.append(
|
|
346
|
+
{
|
|
347
|
+
"name": func["name"],
|
|
348
|
+
"description": func.get("description", ""),
|
|
349
|
+
"input_schema": func.get(
|
|
350
|
+
"parameters",
|
|
351
|
+
{"type": "object", "properties": {}},
|
|
352
|
+
),
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
else:
|
|
356
|
+
anthropic_tools.append(tool)
|
|
357
|
+
else:
|
|
358
|
+
try:
|
|
359
|
+
oai_tool = convert_to_openai_tool(tool)
|
|
360
|
+
func = oai_tool["function"]
|
|
361
|
+
anthropic_tools.append(
|
|
362
|
+
{
|
|
363
|
+
"name": func["name"],
|
|
364
|
+
"description": func.get("description", ""),
|
|
365
|
+
"input_schema": func.get(
|
|
366
|
+
"parameters",
|
|
367
|
+
{"type": "object", "properties": {}},
|
|
368
|
+
),
|
|
369
|
+
}
|
|
370
|
+
)
|
|
371
|
+
except Exception as e:
|
|
372
|
+
logger.warning(
|
|
373
|
+
f"[ChatVertexAIClaude] Failed to convert tool "
|
|
374
|
+
f"{getattr(tool, 'name', tool)}: {e}"
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
return anthropic_tools
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _merge_consecutive_messages(messages: List[Dict]) -> List[Dict]:
|
|
381
|
+
"""Merge consecutive messages with the same role (required by Anthropic API)."""
|
|
382
|
+
if not messages:
|
|
383
|
+
return []
|
|
384
|
+
|
|
385
|
+
merged: List[Dict] = []
|
|
386
|
+
for msg in messages:
|
|
387
|
+
if merged and merged[-1]["role"] == msg["role"]:
|
|
388
|
+
prev_content = merged[-1]["content"]
|
|
389
|
+
curr_content = msg["content"]
|
|
390
|
+
|
|
391
|
+
# Normalize to list of content blocks
|
|
392
|
+
if isinstance(prev_content, str):
|
|
393
|
+
prev_content = [{"type": "text", "text": prev_content}]
|
|
394
|
+
elif not isinstance(prev_content, list):
|
|
395
|
+
prev_content = [prev_content]
|
|
396
|
+
|
|
397
|
+
if isinstance(curr_content, str):
|
|
398
|
+
curr_content = [{"type": "text", "text": curr_content}]
|
|
399
|
+
elif not isinstance(curr_content, list):
|
|
400
|
+
curr_content = [curr_content]
|
|
401
|
+
|
|
402
|
+
merged[-1]["content"] = prev_content + curr_content
|
|
403
|
+
else:
|
|
404
|
+
merged.append(msg)
|
|
405
|
+
|
|
406
|
+
return merged
|