Skip to content

Conversation

@shivammittal274
Copy link
Contributor

No description provided.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 18, 2025

Greptile Summary

  • Adds Google Gemini AI model integration to the BrowserOS agent system by implementing GeminiAgent class, formatter, and registering it in the factory
  • Updates SessionManager with new CANCELLING state and safety timeout mechanism to prevent race conditions during agent cancellation operations
  • Sets Gemini as the default agent type and configures file-based storage for macOS compatibility to avoid keychain prompts

Important Files Changed

Filename Overview
packages/agent/src/agent/GeminiAgent.ts New Gemini agent implementation with MCP server integration, dual config support, and streaming response handling
packages/agent/src/session/SessionManager.ts Added CANCELLING state and safety timeout for robust cancellation; changed default agent to gemini-sdk
packages/agent/src/agent/GeminiAgent.formatter.ts New formatter class that transforms Gemini events into standardized FormattedEvent format

Confidence score: 4/5

  • This PR is largely safe to merge with careful attention to the session state management changes
  • Score reflects solid architecture following established patterns but complexity in SessionManager cancellation logic requires review
  • Pay close attention to SessionManager.ts for potential race conditions in the new CANCELLING state implementation

Sequence Diagram

sequenceDiagram
    participant User
    participant WebSocketServer
    participant SessionManager
    participant GeminiAgent
    participant GeminiClient
    participant MCPServer
    participant ControllerBridge

    User->>WebSocketServer: "Connect WebSocket"
    WebSocketServer->>SessionManager: "createSession(agentConfig)"
    SessionManager->>GeminiAgent: "create agent"
    WebSocketServer-->>User: "connection event"

    User->>WebSocketServer: "send message"
    WebSocketServer->>SessionManager: "markProcessing()"
    WebSocketServer->>GeminiAgent: "execute(message)"
    
    GeminiAgent->>GeminiAgent: "init() - fetch config"
    GeminiAgent->>GeminiClient: "initialize with MCP server"
    GeminiAgent->>GeminiClient: "sendMessageStream()"
    
    loop "Multi-turn conversation"
        GeminiClient-->>GeminiAgent: "stream events"
        GeminiAgent->>GeminiEventFormatter: "format(event)"
        GeminiEventFormatter-->>WebSocketServer: "FormattedEvent"
        WebSocketServer-->>User: "formatted event"
        
        alt "Tool call required"
            GeminiAgent->>MCPServer: "executeToolCall()"
            MCPServer->>ControllerBridge: "browser automation"
            ControllerBridge-->>MCPServer: "tool result"
            MCPServer-->>GeminiAgent: "tool response"
            GeminiAgent->>GeminiClient: "continue with tool results"
        end
    end
    
    GeminiAgent-->>WebSocketServer: "completion event"
    WebSocketServer->>SessionManager: "markIdle()"
    WebSocketServer-->>User: "completion"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

* Gemini CLI Event Formatter
*
* Maps GeminiEventType to FormattedEvent:
* - Content: Accumulate text chunks, emit as 'response'
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Comment says 'emit as response' but formatContent returns null and doesn't emit response events

Suggested change
* - Content: Accumulate text chunks, emit as 'response'
* - Content: Accumulate text chunks (don't emit response events)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agent/src/agent/GeminiAgent.formatter.ts
Line: 12:12

Comment:
**syntax:** Comment says 'emit as response' but formatContent returns null and doesn't emit response events

```suggestion
 * - Content: Accumulate text chunks (don't emit response events)
```

How can I resolve this? If you propose a fix, please make it concise.

* Execute a task using Gemini CLI and stream formatted events
*
* @param message - User's natural language request
* @yields Formatteint instances
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Typo in JSDoc comment: 'Formatteint' should be 'FormattedEvent'

Suggested change
* @yields Formatteint instances
* @yields FormattedEvent instances
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agent/src/agent/GeminiAgent.ts
Line: 181:181

Comment:
**syntax:** Typo in JSDoc comment: 'Formatteint' should be 'FormattedEvent'

```suggestion
   * @yields FormattedEvent instances
```

How can I resolve this? If you propose a fix, please make it concise.

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.

2 participants