Gemini

The Gemini adapter enables Google’s Gemini models to interact with Asset Core through function declarations, mirroring the same tool surface as other adapters.

Prerequisites

  • Asset Core daemons running
  • Google AI API access (Gemini)
  • Python or Rust for integration

Step 1 - Get function declarations

The adapter provides Gemini-compatible function declarations:

use assetcore_adapters::gemini::GeminiToolDefinition;

let tools = GeminiToolDefinition::all();

These declarations follow Google’s function calling schema.

Step 2 - Define functions for Gemini

Format tools for the Gemini API:

from google.generativeai.types import FunctionDeclaration, Tool

commit_function = FunctionDeclaration(
    name="assetcore_commit",
    description="Submit a transaction to Asset Core",
    parameters={
        "type": "object",
        "properties": {
            "operations": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "op": {"type": "string"},
                        "args": {"type": "object"}
                    },
                    "required": ["op", "args"]
                },
                "description": "List of operations to execute"
            },
            "idempotency_key": {
                "type": "string",
                "description": "Optional deduplication key"
            }
        },
        "required": ["operations"]
    }
)

health_function = FunctionDeclaration(
    name="assetcore_write_health",
    description="Check Asset Core write daemon health",
    parameters={"type": "object", "properties": {}}
)

tools = Tool(function_declarations=[commit_function, health_function])

Step 3 - Execute function calls

When Gemini returns a function call, execute it against Asset Core:

import httpx
import json

async def execute_function(name: str, args: dict) -> dict:
    if name == "assetcore_commit":
        async with httpx.AsyncClient() as client:
            response = await client.post(
                "http://localhost:8080/v1/commit",
                json=args
            )
            return response.json()

    elif name == "assetcore_write_health":
        async with httpx.AsyncClient() as client:
            response = await client.get(
                "http://localhost:8080/v1/health"
            )
            return response.json()

    else:
        return {"error": f"Unknown function: {name}"}

Step 4 - Complete conversation loop

Integrate with the Gemini API:

import google.generativeai as genai

genai.configure(api_key="your-api-key")
model = genai.GenerativeModel(
    "gemini-pro",
    tools=[tools]
)

chat = model.start_chat()

response = chat.send_message(
    "Create a container with ID 1001"
)

# Check for function calls
if response.candidates[0].content.parts[0].function_call:
    fc = response.candidates[0].content.parts[0].function_call

    # Execute the function
    result = await execute_function(fc.name, dict(fc.args))

    # Send the result back
    response = chat.send_message(
        genai.protos.Content(
            parts=[
                genai.protos.Part(
                    function_response=genai.protos.FunctionResponse(
                        name=fc.name,
                        response={"result": result}
                    )
                )
            ]
        )
    )

    print(response.text)

Step 5 - Use the Rust executor

For Rust applications:

use assetcore_adapters::gemini::GeminiToolExecutor;
use assetcore_adapters::http_client::DaemonClient;

let client = DaemonClient::new(
    "http://localhost:8080",
    "http://localhost:8081"
);

let executor = GeminiToolExecutor::new(client);

let result = executor.execute(
    "assetcore_commit",
    serde_json::json!({
        "operations": [
            {
                "op": "CreateContainer",
                "args": {
                    "container_id": 1001,
                    "kind": "Standard"
                }
            }
        ]
    })
).await?;

Troubleshooting

Function not recognized

Ensure the function name matches exactly. Gemini is case-sensitive.

Invalid arguments

Gemini may generate arguments that don’t match the schema. Add validation before execution.

Multiple function calls

Gemini may request multiple function calls. Execute them sequentially for Asset Core.

Next steps