Add GeminiAgent for Google Gemini model support#451
Conversation
Implement GeminiAgent and GeminiAgentOptions following the same pattern as OpenAIAgent, using the google-genai SDK. Supports both streaming and non-streaming responses, system prompts, retriever integration, and pre-configured client injection. - New file: agents/gemini_agent.py - Conditional import in agents/__init__.py (graceful when google-genai not installed) - New 'gemini' optional dependency group in setup.cfg - GEMINI_MODEL_ID_GEMINI_2_0_FLASH constant in types Fixes 2FastLabs#376
Unit tests cover initialization, client injection, custom prompts, streaming/non-streaming requests, retriever integration, and error handling. Integration test validates Vertex AI connectivity (requires GOOGLE_APPLICATION_CREDENTIALS). Registers 'integration' pytest marker.
|
Hey @gavksingh, a few things need to be fixed before this can merge. Three are required: (1) there is no Two smaller things that are not blocking: |
Summary
GeminiAgentandGeminiAgentOptionsfor integrating Google Gemini models via thegoogle-genaiSDKOpenAIAgent— supports streaming/non-streaming, system prompts, retriever integration, and pre-configured client injectiongeminioptional dependency group (pip install agent-squad[gemini])google-genaiis not installed (conditional import)Files Changed
python/src/agent_squad/agents/gemini_agent.py— new agent implementationpython/src/agent_squad/agents/__init__.py— conditional import for GeminiAgentpython/setup.cfg—geminiextras group withgoogle-genai>=1.0.0python/src/agent_squad/types/types.py—GEMINI_MODEL_ID_GEMINI_2_0_FLASHconstantpython/src/agent_squad/types/__init__.py— export the new constantpython/src/tests/agents/test_gemini_agent.py— new test filepython/src/tests/pytest.ini— registeredintegrationmarkerTests added
New file:
python/src/tests/agents/test_gemini_agent.py(8 unit tests + 1 integration test)Unit tests:
test_gemini_agent_requires_api_key_or_client— ValueError when neither providedtest_gemini_agent_client_injection— pre-configured client bypasses api_key requirementtest_custom_system_prompt_with_variable— template{{variable}}resolved correctlytest_process_request_success— non-streaming returns ConversationMessagetest_process_request_streaming— streaming yields AgentStreamResponse chunks + final_messagetest_process_request_with_retriever— retriever called, context appendedtest_process_request_api_error— exception propagationtest_is_streaming_enabled— False default, True when setIntegration test (requires credentials):
test_gemini_vertex_ai_integration— end-to-end via Vertex AI withGOOGLE_APPLICATION_CREDENTIALSRun integration test with:
Test plan
from agent_squad.agents import GeminiAgentworks withgoogle-genaiinstalledgoogle-genaiis NOT installedpytest -v -m "not integration")Fixes #376