Skip to content

Mutimodule - #288

Open
rhinewg wants to merge 7 commits into
Ingenimax:mainfrom
rhinewg:mutimodule
Open

Mutimodule#288
rhinewg wants to merge 7 commits into
Ingenimax:mainfrom
rhinewg:mutimodule

Conversation

@rhinewg

@rhinewg rhinewg commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

[FEATURE] Support multimodal input #272

Description

This PR adds multimodal input support so users can send not only text but also images when interacting with agents. The library previously only supported text input; this change extends the CLI, HTTP microservice server, and optional Web UI to accept image URLs, local image files, and multipart file uploads.

Summary of changes:

  • Interfaces / schema: Request payloads support optional content_parts (e.g. text and image_url parts) in addition to the existing input text field. Image URLs may be http://, https://, or data: (base64) and are validated for scheme and MIME type where applicable.
  • agent-cli: New flags --image-url and --image-path to attach images (URLs or local paths). Local file reads are scoped to the current directory via os.OpenRoot (Go 1.24) to prevent path traversal (gosec G304).
  • HTTP server (pkg/microservice):
    • JSON API: optional content_parts in the request body.
    • Multipart API: images/image file fields, optional upload_mode (data URL vs store), and optional content_parts JSON field.
    • Upload directory uses restricted permissions (0o750); uploaded files are 0o600 (gosec G301/G306).
  • Web UI (when using HTTPServerWithUI): Chat UI supports attaching images and sending them as content_parts (e.g. data URL or stored file URL). Display content is separated from payload content where needed for correct rendering.
  • Example: New example examples/microservices/ui_multimodal_server demonstrating the UI and multimodal API.
  • Lint & security: Addressed golangci-lint (staticcheck ST1005, S1030) and gosec (G304, G301, G306) findings in the touched code paths.

Voice input is out of scope for this PR and can be addressed in a follow-up (e.g. speech-to-text then text input, or first-class audio parts if/when the project supports it).

Fixes #272

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Build: go build ./... and building cmd/agent-cli and examples/microservices/ui_multimodal_server.
  • Linters: golangci-lint run ./cmd/agent-cli/... ./pkg/microservice/... (0 issues); gosec run on the same paths (G304, G301, G306 resolved).
  • Unit tests: go test ./pkg/microservice/... (including http_server_test.go for multipart and file handling).
  • Manual:
    • agent-cli with --image-url / --image-path.
    • HTTP server with JSON body containing content_parts with image_url.
    • HTTP server with multipart form and images file upload.
    • Web UI: open http://localhost:8085/ (or configured port), attach image, send message and confirm request uses content_parts.

Reproduce: run go run ./examples/microservices/ui_multimodal_server, open the UI URL, attach an image and send a prompt; optionally call the HTTP API with content_parts or multipart from another client.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

rhinewg and others added 7 commits January 19, 2026 11:51
…nd providers

- Introduce ContentPart-based multimodal schema and context propagation.
- Add OpenAI, Anthropic, and Gemini adapters for image_url content parts.
- Enable microservice JSON + multipart image uploads (data_url default; store mode gated by AGENT_SDK_UPLOAD_DIR) with URL/mime validation.
- Extend agent-cli with --image/--image-url flags and :image chat attachments.
- Allow UI /agent/run and /agent/stream to accept content_parts (input or parts required)
- Add image picker in Next.js UI and send images as data URLs via content_parts
- Update UI request types and refresh embedded static UI build output
- Replace native file input with button-triggered hidden input for consistent layout.
- Add optional ChatMessage.display_content for UI-friendly rendering.
- Fix UI lint blockers (effects/state, remove explicit any casts).
- Regenerate embedded Next.js out/ assets.
- Add ui_multimodal_server example docs and starter.
golangci-lint (staticcheck):
- ST1005: error strings lowercase, no trailing punctuation
  (cmd/agent-cli/multimodal.go, pkg/microservice/http_server.go)
- S1030: use getW.Body.String() in http_server_test.go

gosec:
- G304: restrict file read to cwd via os.OpenRoot (multimodal.go)
- G301: upload dir permissions 0o755 -> 0o750 (http_server.go)
- G306: uploaded file permissions 0o644 -> 0o600 (http_server.go)

### 5. UI Multimodal Server (`ui_multimodal_server/`)

演示如何启动带 **内置 UI** 的 HTTP 服务(`HTTPServerWithUI`),并包含一个 `client` 使用用例:从命令行读取图片并以 `content_parts` 调用 `/api/v1/agent/run` 验证多模态链路。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, could you translate this text to English?

@sushi30

sushi30 commented May 2, 2026

Copy link
Copy Markdown

@meidad That PR seems to haven't moved in more than 2 months and seems incomplete with things like front end artifacts. The user seems to be very sporadically on GitHub without any activity since February. Mind if I pick it up and finalize it?

@meidad

meidad commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Solid feature — image inputs across CLI, microservice, and all three LLM providers (OpenAI, Anthropic, Gemini) in one PR. The security attention (G304/G301/G306) is appreciated.

One blocker and one question:

Required

  1. Don't commit compiled Next.js assets. The pkg/microservice/ui-nextjs/out/ directory contains generated build output (_next/static/chunks/, _buildManifest.js, etc.). Committing compiled frontend assets creates noise, causes merge conflicts, and means the binary in the repo can silently diverge from the source. The out/ directory should be excluded from the PR — either via .gitignore, or built at deploy/embed time. Please remove those files from this PR.

Questions

  1. The os.OpenRoot path traversal fix is Go 1.24+. What's the project's minimum supported Go version? If it's < 1.24 this will break CI.

Nice-to-have

  1. A rebase against current main would be good — this is 4+ months old and there have been changes to pkg/agent/agent.go and pkg/interfaces/llm.go.

The core multimodal logic looks clean. Happy to merge once the compiled assets are removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] support multimodal input

4 participants