Experimental Gemini FunctionDeclaration adapter for Stigmem.
Project description
stigmem-plugin-gemini-adapter
Integrates Stigmem with the Google Gemini API using Gemini's native FunctionDeclaration format.
This package is experimental and opt-in. Installing it makes the
gemini-adapter plugin discoverable through the stigmem.plugins entry-point
group; host applications still choose when to call the adapter.
Design
The adapter has three surfaces:
-
gemini_tools()— returnsSTIGMEM_FUNCTION_DECLARATIONS, alist[dict]of GoogleFunctionDeclaration-shaped JSON objects ready to pass togenai.protos.FunctionDeclaration(**t)or directly to the REST API. -
dispatch(fn_name, fn_args)— executes a Stigmem tool call triggered by a GeminiFunctionCallpart and returns a JSON string to wrap in aFunctionResponse. -
run(system_prompt, user_message)— a thin agentic loop that handles the full tool-use turn sequence. Requiresgoogle-generativeaiinstalled.
The adapter depends on Stigmem's Python client surface. The
google-generativeai SDK is an optional dependency needed only for run().
Files
| File | Purpose |
|---|---|
src/stigmem_plugin_gemini/adapter.py |
Adapter — function declarations + dispatch + agentic loop |
src/stigmem_plugin_gemini/manifest.py |
Stigmem plugin discovery manifest |
tests/conftest.py |
pytest path setup |
tests/test_adapter.py |
Unit tests (respx-mocked) |
Installation
python -m pip install 'stigmem-plugin-gemini-adapter>=0.1.0,<2.0.0'
Install the Gemini SDK only in deployments that use the convenience
run() loop:
python -m pip install 'stigmem-plugin-gemini-adapter[gemini]>=0.1.0,<2.0.0'
Requirements
- Python ≥ 3.11
stigmem-py:pip install stigmem-py(or from workspace)google-generativeai: optional runtime extra forrun(); function declarations, dispatch, unit tests, and plugin discovery do not require it.
Environment variables
STIGMEM_URL=http://localhost:8765
STIGMEM_API_KEY=sk-your-key # optional
STIGMEM_SOURCE_ENTITY=agent:gemini # entity URI for this agent
STIGMEM_GEMINI_MODEL=gemini-2.0-flash # model to use in run()
GOOGLE_API_KEY=your-gemini-key # required for run()
Usage
Raw declarations (no Gemini SDK needed)
from stigmem_plugin_gemini import STIGMEM_FUNCTION_DECLARATIONS
# Pass to any Gemini-compatible API as plain JSON
print(STIGMEM_FUNCTION_DECLARATIONS[0]["name"]) # → "assert_fact"
With the Gemini SDK
import google.generativeai as genai
from stigmem_plugin_gemini import StigmemGeminiAdapter
genai.configure(api_key="your-gemini-key")
adapter = StigmemGeminiAdapter.from_env()
tool_obj = genai.protos.Tool(
function_declarations=[
genai.protos.FunctionDeclaration(**t)
for t in adapter.gemini_tools()
]
)
model = genai.GenerativeModel(
model_name="gemini-2.0-flash",
system_instruction="You are an agent with access to a shared knowledge base.",
tools=[tool_obj],
)
chat = model.start_chat()
response = chat.send_message("What facts exist about project:acme-platform?")
# Dispatch tool calls
for part in response.candidates[0].content.parts:
if part.function_call:
result_json = adapter.dispatch(part.function_call.name, dict(part.function_call.args))
# wrap result_json in a FunctionResponse and continue the loop
Agentic loop (convenience)
import google.generativeai as genai
from stigmem_plugin_gemini import StigmemGeminiAdapter
genai.configure(api_key="your-gemini-key")
adapter = StigmemGeminiAdapter.from_env()
answer = adapter.run(
system_prompt="You are a helpful agent with access to a shared knowledge base.",
user_message="Summarise all active roadmap constraints for project:acme.",
)
print(answer)
Enable
The adapter has no node-global behavior gate at v0.1.0. Enable it in the host
application by installing the package and importing
stigmem_plugin_gemini.StigmemGeminiAdapter.
python -m pip install 'stigmem-plugin-gemini-adapter>=0.1.0,<2.0.0'
python -m pip install 'stigmem-plugin-gemini-adapter[gemini]>=0.1.0,<2.0.0' # live Gemini loop
stigmem plugins list
Disable
Remove the adapter from the host application path and restart the process that loads plugins. If it was installed only for this integration, uninstall it:
python -m pip uninstall stigmem-plugin-gemini-adapter
Test
cd stigmem
uv run pytest experimental/gemini-adapter/tests/ -v
No live node or Gemini API key required — all HTTP calls are mocked with respx.
Uninstall
python -m pip uninstall stigmem-plugin-gemini-adapter
Protocol notes
- Gemini uses
"OBJECT","STRING","NUMBER","BOOLEAN","INTEGER","ARRAY"as type strings (upper-case). This differs from JSON Schema / OpenAI which use lower-case. - The
run()loop caps atmax_rounds=10to prevent infinite tool-call cycles. - Tool dispatch errors are caught and returned as
{"error": "..."}JSON so the model can reason about failures rather than crashing the loop.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stigmem_plugin_gemini_adapter-0.1.0.tar.gz.
File metadata
- Download URL: stigmem_plugin_gemini_adapter-0.1.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3212c683acbabde604ed7343660ad6cd2d8c581e1cc76ccc9c350eb5e9ff941
|
|
| MD5 |
e08db7819c017869483eeb25d933073b
|
|
| BLAKE2b-256 |
cacefa35702cb7742b856eb56b802614845da4424203fdc19375d217503139d3
|
Provenance
The following attestation bundles were made for stigmem_plugin_gemini_adapter-0.1.0.tar.gz:
Publisher:
publish.yml on eidetic-labs/stigmem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stigmem_plugin_gemini_adapter-0.1.0.tar.gz -
Subject digest:
d3212c683acbabde604ed7343660ad6cd2d8c581e1cc76ccc9c350eb5e9ff941 - Sigstore transparency entry: 1707430240
- Sigstore integration time:
-
Permalink:
eidetic-labs/stigmem@5fcb5ce3da27ead0e99d41d34fea319601190158 -
Branch / Tag:
refs/tags/v0.9.0a10 - Owner: https://github.com/eidetic-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5fcb5ce3da27ead0e99d41d34fea319601190158 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stigmem_plugin_gemini_adapter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stigmem_plugin_gemini_adapter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73fe41ab8bb84890d6f56b77089c3e5fea6323063bf7b6b2d3c244fd25fb8c7a
|
|
| MD5 |
07ca3eb670912ce093001a120eefa410
|
|
| BLAKE2b-256 |
9feaa8984fad78542733c5283cbeb5fd1242167e37d16bceb7de5c74bea1018f
|