-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix: Add environment variable check for ANTHROPIC_API_BASE #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit updates the environment variable checks in `backend/src/agent/graph.py` to include `ANTHROPIC_API_BASE`. LiteLLM automatically uses this environment variable to route Anthropic API calls to a custom endpoint if set. This change ensures that the application raises an informative error if this variable is expected by your setup but not provided. The `required_env_vars` dictionary now includes an entry for `ANTHROPIC_API_BASE` with a message clarifying its purpose for you if you are employing a proxy or custom Anthropic API endpoint.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This commit changes the import statements within `backend/src/agent/graph.py` to use relative imports (e.g., `from .tools_and_schemas import ...` instead of `from agent.tools_and_schemas import ...`). This change addresses a `ModuleNotFoundError: No module named 'agent'` that occurred when running the application with `langgraph dev`. Relative imports ensure that modules within the 'agent' package can correctly locate and import their siblings when the application is loaded by the LangGraph development server.
This commit adds an empty `__init__.py` file to the `backend/src` directory. This explicitly defines `src` as a Python package. This change is intended to help resolve import errors, specifically `ImportError: attempted relative import with no known parent package`, that can occur when running the application if the package structure is not clearly defined or the project is not installed in editable mode. The `backend/src/agent/__init__.py` file was confirmed to already exist.
This commit reverts the import statements in `backend/src/agent/graph.py` from relative imports (e.g., `from .tools_and_schemas import ...`) back to absolute imports (e.g., `from agent.tools_and_schemas import ...`). The previous attempts to use relative imports resulted in `ImportError: attempted relative import with no known parent package`. This, along with the original `ModuleNotFoundError: No module named 'agent'`, strongly indicates that the root cause of the import issues is not the style of import statement within the file, but rather that the Python execution environment (specifically when running via `langgraph dev`) does not recognize `backend/src` or `backend/src/agent` as a discoverable package. The solution for such issues typically involves ensuring the project is properly packaged (e.g., with a `pyproject.toml` or `setup.py` file) and then installed in editable mode (`pip install -e .`). This makes the local packages like `agent` known to the Python import system. This revert prepares the codebase for that environment setup, as absolute imports should function correctly once the package is properly installed and discoverable.
This commit modifies `backend/src/agent/app.py` to explicitly add the `backend/src` directory to `sys.path` at runtime. This change is a diagnostic step to address persistent `ModuleNotFoundError: No module named 'agent'` errors when running the application with `langgraph dev`, even after attempting an editable install (`pip install -e .`). By prepending the calculated `src` directory to `sys.path` at the beginning of `app.py` (the entry point for `langgraph dev`), this change aims to ensure that the Python interpreter can locate the `agent` package and its modules. If this resolves the import error, it indicates an issue with how `langgraph dev` environment discovers packages installed in editable mode, or how the editable installation itself is configured via `pyproject.toml` or `setup.py`.
…cies
This commit addresses persistent ModuleNotFoundError issues when running
`langgraph dev` by correctly configuring `backend/pyproject.toml`
to recognize the `src` directory layout.
Key changes:
1. Modified `backend/pyproject.toml`:
- Added `package_dir = {"" = "src"}` to the `[project]` table,
directing setuptools to look for packages within the `src`
subdirectory.
- Added `packages = ["agent"]` to explicitly include the `agent`
package.
- Updated `[project.dependencies]` to include `litellm`,
`anthropic`, `firecrawl-py`, and removed direct Google GenAI
dependencies (`langchain-google-genai`, `google-genai`).
(Note: `google-api-python-client` and `google-searchresults`
were kept for now, pending your review of their necessity).
2. Removed `backend/requirements.txt`: Dependencies are now solely
managed by `pyproject.toml`.
3. Reverted `sys.path` modification in `backend/src/agent/app.py`:
The explicit `sys.path` manipulation is no longer needed with the
correct `pyproject.toml` setup and an editable install.
These changes ensure that when the project is installed in editable
mode (`pip install -e .` from the `backend` directory), Python's
import system can correctly locate the `agent` package and its modules
from the `backend/src` directory. This should resolve the import errors
encountered with `langgraph dev`.
|
Thank you for opening the PR. We are closing it, as build this quickstart to help developers and builders to get started building Agents using Gemini. It is great to see you evolving it, but for now we keep it as it is. Feel free to continue it as your own project. |
This commit updates the environment variable checks in
backend/src/agent/graph.pyto includeANTHROPIC_API_BASE.LiteLLM automatically uses this environment variable to route Anthropic API calls to a custom endpoint if set. This change ensures that the application raises an informative error if this variable is expected by your setup but not provided.
The
required_env_varsdictionary now includes an entry forANTHROPIC_API_BASEwith a message clarifying its purpose for you if you are employing a proxy or custom Anthropic API endpoint.