Skip to content

feat(model): add native Gemini chat integration - #54

Draft
nanami7777777 wants to merge 1 commit into
agentscope-ai:mainfrom
nanami7777777:feat/gemini-chat-model
Draft

nanami7777777 wants to merge 1 commit into
agentscope-ai:mainfrom
nanami7777777:feat/gemini-chat-model

Conversation

@nanami7777777

Copy link
Copy Markdown

Linked Issues

Closes #7. Related to the provider portion of #49.

PR #42 references #7 but implements Grok, not Gemini. This PR implements the Gemini scope requested in #7 against current upstream main.

Description

Add GeminiChatModel and GeminiChatFormatter using the native Gemini Developer API REST endpoints, following the existing fetch-based provider architecture.

  • Streaming and non-streaming text/thinking/function-call responses, including parallel calls.
  • Unified auto, none, required and named tool choice; function declarations retain their JSON Schema using parametersJsonSchema.
  • Native system instructions, inline base64/file-URI input, generation settings, safety settings and request cancellation.
  • Group parallel function responses into a single user turn.
  • Preserve opaque part signatures through response parsing, message serialization and history formatting. Text/tool-call/data block constructors and schemas accept an optional thought_signature; unsigned existing blocks are unchanged.
  • Accumulate streaming deltas without mutating earlier yields, retain terminal usage-only chunks, count thought tokens, and cancel the response reader when the consumer stops.
  • Export both public classes and document the API, streaming return value and limitations.

The tests include an actual Agent + Toolkit lifecycle with mocked Gemini HTTP responses: the agent executes a returned function, then sends its result and the original signature in the next model request. Additional tests cover serialized history, parallel results, structured output, fragmented UTF-8/CRLF SSE, late signatures, terminal usage, cancellation and errors.

Verification

  • pnpm --filter @agentscope-ai/agentscope exec jest --runInBand --silent: 21 suites, 145 tests passed.
  • pnpm --filter @agentscope-ai/agentscope build: CJS, ESM and declarations passed.
  • pnpm build:desktop: type checks and build passed.
  • Changed-file ESLint and Prettier checks passed; repository commit hooks passed.
  • Built CJS and ESM exports were loaded and the Gemini classes instantiated successfully.
  • git diff --check: passed.

Build emits the repository's existing message-barrel declaration-cycle warnings; no unrelated package-boundary refactor is included.

Scope and limitations

This implements the Gemini Developer API, not Vertex AI or the Interactions API. It uses the first response candidate. Function arguments are received as complete objects; experimental partial function-argument streaming is outside this PR. File URLs are passed as Gemini file URIs, not fetched automatically. Unit and integration tests use mocked HTTP responses; no credentialed live Gemini call was performed.

Prepared with Codex assistance. Submitted as a draft for contribution-author review and maintainer feedback, including coordination with #49.

Checklist

  • Linked to a related issue
  • Changed files formatted and linted with the repository tooling
  • Related usage documentation updated
  • All core tests pass
  • Contribution author has reviewed the changes and code is ready for formal review

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.

feat: support Gemini API and add unit tests

1 participant