The Agent framework provides a platform-agnostic foundation for building autonomous AI agents with tool execution capabilities. It builds upon the existing Gemini CLI core infrastructure while maintaining clean abstractions for extensibility.
packages/agent/
├── src/
│ ├── interfaces.ts # Platform-agnostic interfaces
│ ├── geminiChat.ts # Gemini-specific chat implementation
│ └── index.ts # Main exports
├── examples/
│ ├── calculateTool.ts # Tool implementation example
│ └── weatherTool.ts # Tool implementation example
├── framework.md # This documentation
├── plan.md # Implementation plan
├── package.json # Package configuration
├── tsconfig.json # TypeScript configuration
├── tsconfig.standalone.json # Standalone build configuration
└── README.standalone.md # Standalone package documentation
┌─────────────────────────────────────────────────────────────────┐
│ Agent Framework │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ IAgent │ │ IChat │ │ IToolScheduler │ │
│ │ (Core Logic) │ │ (Conversation) │ │ (Tool Execution)│ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ GeminiChat │ │ ToolScheduler │ │ TokenTracker │ │
│ │ (Implementation)│ │ Adapter │ │ (Usage Monitor) │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ Integration with @google/gemini-cli-core │
└─────────────────────────────────────────────────────────────────┘
Purpose: Define platform-agnostic interfaces for all agent components
Key Interfaces:
IAgent: Main agent interface with conversation processingIChat: Chat management with streaming supportIToolScheduler: Tool execution coordinationITool: Tool definition and executionITokenTracker: Token usage monitoring
Benefits:
- Platform independence
- Type safety
- Clear contracts
- Easy testing and mocking
Purpose: Gemini-specific chat implementation with streaming support
Key Features:
- Streaming-only responses
- Real-time token tracking
- History management
- Response validation
- Error handling
Integration Points:
- Uses
@google/gemini-cli-coreContentGenerator - Implements
IChatinterface - Integrates with TokenTracker
Purpose: Seamless integration with existing tool infrastructure
Approach:
- Use existing
CoreToolSchedulerfrom core package - Adapter pattern for interface compatibility
- Maintain existing tool definitions
- Support all tool types (built-in, MCP, custom)
User Input
↓
┌─────────────────────┐
│ IAgent │
│ (Main Controller) │
└─────────────────────┘
↓
┌─────────────────────┐
│ IChat │
│ (Conversation) │
└─────────────────────┘
↓
┌─────────────────────┐
│ ContentGenerator │
│ (LLM Interface) │
└─────────────────────┘
↓
┌─────────────────────┐
│ Streaming Response │
│ (Real-time Output) │
└─────────────────────┘
↓
┌─────────────────────┐
│ Tool Extraction │
│ (Parse Tool Calls) │
└─────────────────────┘
↓
┌─────────────────────┐
│ IToolScheduler │
│ (Tool Execution) │
└─────────────────────┘
↓
┌─────────────────────┐
│ Tool Results │
│ (Back to Chat) │
└─────────────────────┘
┌─────────────────────┐
│ User Message │
└─────────────────────┘
↓
┌─────────────────────┐
│ Agent.process() │
│ - Validate input │
│ - Start streaming │
└─────────────────────┘
↓
┌─────────────────────┐
│ Chat.sendMessage │
│ - Create request │
│ - Send to LLM │
└─────────────────────┘
↓
┌─────────────────────┐
│ Streaming Chunks │
│ - Content events │
│ - Token tracking │
└─────────────────────┘
↓
┌─────────────────────┐
│ Tool Extraction │
│ - Parse calls │
│ - Create requests │
└─────────────────────┘
↓
┌─────────────────────┐
│ Tool Execution │
│ - Schedule calls │
│ - Handle results │
└─────────────────────┘
↓
┌─────────────────────┐
│ History Update │
│ - Add to history │
│ - Emit events │
└─────────────────────┘
- Interfaces work with any LLM provider
- No hard dependencies on specific implementations
- Easy to extend for new providers
- Real-time response processing
- Immediate user feedback
- Efficient resource usage
- Comprehensive event emission
- Real-time monitoring
- Easy integration with UI/logging
- Real-time token tracking
- Usage monitoring
- Limit management
- Seamless tool execution
- Existing tool compatibility
- Extensible tool system
- Implement
GeminiChatbased on core package - Add streaming-only support
- Integrate token tracking
- Maintain history management
- Create
ToolSchedulerAdapter - Integrate with
CoreToolScheduler - Maintain existing tool compatibility
- Support all tool types
- Create minimal
Agentclass - Focus on conversation flow
- Integrate chat and tools
- Event emission system
- Performance optimization
- Error handling improvement
- Documentation completion
- Testing coverage
- Minimal Dependencies: Only depends on core package
- Clean Abstractions: Clear separation of concerns
- Extensibility: Easy to add new providers/features
- Compatibility: Works with existing tool ecosystem
- Performance: Streaming-first approach
- Monitoring: Comprehensive event system
- Type Safety: Full TypeScript support
This framework provides a solid foundation for building autonomous AI agents while maintaining simplicity and extensibility.