Skip to main content

A Python multimodal agent for interacting with Gemini models via text, images, and CLI.

Project description

Multimodal-Agent

A lightweight, production-ready multimodal wrapper for Google Gemini with optional RAG, image input, JSON mode, and a clean CLI.


Features

  • 🔹 Text generation (Gemini)
  • 🔹 Image + text multimodal input
  • 🔹 Retry logic with exponential backoff
  • 🔹 JSON response mode (response_format="json")
  • 🔹 Dummy offline mode (no API key required)
  • 🔹 Clean CLI (agent)
  • 🔹 90%+ test coverage
  • 🔹 Chunking + RAG store (simple & embeddable)
  • 🔹 Session history + memory
  • 🔹 Extensible architecture for VS Code / Flutter integration

Installation

pip install multimodal-agent

Or install a specific version:

pip install multimodal-agent==0.3.0

Setup API Key (Optional)

If you want real Gemini output:

export GOOGLE_API_KEY="your-key-here"

Without a key, the package still works using offline FakeResponse for testing & debugging.

Basic Usage

from multimodal_agent import MultiModalAgent

agent = MultiModalAgent(enable_rag=False)

print(agent.ask("Explain quantum physics to me."))

Ask With Image

from multimodal_agent import MultiModalAgent
from multimodal_agent.utils import load_image_as_part

agent = MultiModalAgent(enable_rag=False)

image = load_image_as_part("cat.jpg")
print(agent.ask_with_image("Describe this image.", image))

JSON Response Mode

RAG Mode (Optional)

You can request structured JSON output by passing response_format="json":

from multimodal_agent import MultiModalAgent

agent = MultiModalAgent(enable_rag=False)

result = agent.ask("Return a JSON object with a and b.", response_format="json")
print(result.data)   # {'a': 1, 'b': 'hello'}

The agent automatically:

  • Strips ```json fenced blocks
  • Parses JSON
  • Falls back to {"raw": <text>} when invalid JSON is returned
  • Maintains identical behavior in online and offline mode

Offline Mode

If no GOOGLE_API_KEY is found, the agent enters offline simulation mode:

  • No real API calls are made
  • Responses are deterministic and prefixed with "FAKE_RESPONSE:"
  • JSON mode still returns proper {}-dicts
  • Usage metadata is simulated for testing

This ensures the package is fully testable without credentials.

AgentResponse Object

All .ask() and .chat() calls return:

AgentResponse(
    text="<model text>",
    data={...},          # JSON dict if json mode, else None
    usage={
        "prompt_tokens": ...,
        "response_tokens": ...,
        "total_tokens": ...,
    }
)

Asking With Images

from multimodal_agent.utils import load_image_as_part

img = load_image_as_part("photo.jpg")
resp = agent.ask_with_image("Describe this image", img)
print(resp.text)

Enable RAG:

agent = MultiModalAgent(enable_rag=True)
agent.ask("First message")
agent.ask("Second message referencing the first")

RAG stores:

  • chunked logs
  • embeddings
  • search similarity

This makes your CLI "memory aware".

CLI Usage

agent

Then interactive chat:

You: hello
Agent: ...

Quit:

You: exit

Running Tests

make test
make coverage

Test coverage: ~91%

Architecture Overview

agent_core.py — main agent logic

chunking.py — text chunking & normalization

embedding.py — embedding wrappers

rag_store.py — vector search store

cli.py — command line interface

utils.py — image loading, memory, history helpers

Roadmap

v0.3.2 — Token usage logging

v0.4.0 — Flutter-friendly structured outputs

v0.5.0 — VS Code extension alpha

v0.6.0 — Android Studio plugin

v1.0.0 — Public launch (website + demos + docs)

License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multimodal_agent-0.3.1.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multimodal_agent-0.3.1-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file multimodal_agent-0.3.1.tar.gz.

File metadata

  • Download URL: multimodal_agent-0.3.1.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for multimodal_agent-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0ebc34b937ecce0d6f1cb54966adef8ac0589bcbe2859568066dea7fa36b0047
MD5 67dcb4133c4fa22c87f198e7f5de1558
BLAKE2b-256 cbd0aa2365b3809a7c63d77e83c6f1f1c4b9a5fb23a28ec3c730fadf4278aac8

See more details on using hashes here.

File details

Details for the file multimodal_agent-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for multimodal_agent-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d293f05d48df0ffd5c305c1c10b8869a208d9e80f7684436204d50e43b41f988
MD5 adffd1d6c911ca397e83e98b8587416d
BLAKE2b-256 7a736250fe6ba301d18169246ed561d864a88088b8b5ce607a70c8dbff966dae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page