gas-agent v1.0.0
GAS Agent
A powerful Google Apps Script library for integrating AI agents with multiple Language Model providers. This library makes it easy to use various AI models in your Google Apps Script projects with a unified, simple interface.
Features
- Support for multiple AI providers:
- OpenAI (GPT-3.5, GPT-4)
- Google AI (Gemini)
- DeepSeek
- OpenRouter
- Groq
- Custom OpenAI-compatible endpoints
- Conversation history management
- System prompt customization
- TypeScript support
- Easy integration with Google Apps Script
Usage Approaches
There are two ways to use GAS Agent in your Google Apps Script projects:
1. Direct Google Apps Script IDE Integration
- Create a new Google Apps Script project at script.google.com
- Copy the contents of
gas/Code.gs
into your project - (Optional) Copy
gas/Example.gs
for reference implementations
This approach is ideal for:
- Quick prototyping
- Simple projects
- Users who prefer working directly in the Google Apps Script IDE
2. NPM Package with Clasp
- Install the package:
npm install gas-agent
- Set up clasp in your project:
npm install -g @google/clasp
clasp login
clasp create --type standalone
- Push your changes to Google Apps Script:
npm run push
This approach is recommended for:
- Larger projects
- TypeScript development
- Version control integration
- Modern development workflow
API Key Configuration
You have two options for configuring API keys:
1. Script Properties (Recommended)
Set up your API keys securely using Google Apps Script's Script Properties:
function setupApiKeys() {
const scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
'OPENAI_API_KEY': 'your-openai-api-key',
'GOOGLEAI_API_KEY': 'your-googleai-api-key',
'DEEPSEEK_API_KEY': 'your-deepseek-api-key',
'OPENROUTER_API_KEY': 'your-openrouter-api-key',
'GROQ_API_KEY': 'your-groq-api-key'
});
}
2. Direct Configuration
Provide API keys directly in the agent configuration:
const agent = gasAgent.createAgent('myAgent', 'OpenAI', {
apiKey: 'your-openai-api-key',
model: 'gpt-3.5-turbo'
});
Note: The Script Properties approach is more secure and recommended for production use.
Usage Examples
Basic Example
function example() {
const gasAgent = new GASAgent();
// Create an agent with OpenAI
const agent = gasAgent.createAgent('myAgent', 'OpenAI', {
model: 'gpt-3.5-turbo',
temperature: 0.7,
max_tokens: 100
});
// Query the agent
const response = agent.query('What is the capital of France?');
Logger.log(response);
}
Chat Example with History
function chatExample() {
const gasAgent = new GASAgent();
const agent = gasAgent.createAgent('chatAgent', 'OpenAI', {
model: 'gpt-3.5-turbo',
systemPrompt: 'You are a helpful assistant who speaks in a friendly manner.'
});
// First interaction
const response1 = agent.query('What is your favorite color?');
// Second interaction (includes context from first interaction)
const response2 = agent.query('Why do you like that color?');
// View chat history
const history = agent.getHistory();
// Clear history if needed
agent.clearHistory();
}
Multiple Providers Example
function multiProviderExample() {
const gasAgent = new GASAgent();
const openaiAgent = gasAgent.createAgent('openaiAgent', 'OpenAI', {
model: 'gpt-4'
});
const geminiAgent = gasAgent.createAgent('geminiAgent', 'GoogleAI', {
model: 'gemini-2.0-flash'
});
const groqAgent = gasAgent.createAgent('groqAgent', 'Groq', {
model: 'mixtral-8x7b-32768'
});
// Compare responses
const prompt = 'Explain quantum computing in simple terms.';
const responses = {
openai: openaiAgent.query(prompt),
gemini: geminiAgent.query(prompt),
groq: groqAgent.query(prompt)
};
}
API Reference
GASAgent Class
createAgent(agentName: string, providerName: ProviderName, config: ProviderConfig): Agent
listAgents(): string[]
listProviders(): ProviderName[]
Agent Interface
setSystemPrompt(prompt: string): void
clearHistory(): void
getHistory(): Message[]
query(input: string, keepHistory?: boolean): ProviderResponse
Provider Configuration
interface ProviderConfig {
apiKey?: string;
model?: string;
systemPrompt?: string;
temperature?: number;
max_tokens?: number;
baseURL?: string; // For OpenAILike provider
referer?: string; // For OpenRouter
title?: string; // For OpenRouter
}
License
MIT
Contributing
We welcome contributions to GAS Agent! Here's how you can help:
Development Setup
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/gas-agent.git
cd gas-agent
- Install dependencies:
npm install
- Set up Google Apps Script development environment:
npm install -g @google/clasp
clasp login
clasp create --type standalone
Development Workflow
- Create a new branch for your feature/fix:
git checkout -b feature-name
- Make your changes
- Run tests:
npm test
- Build the project:
npm run build
- Push to Google Apps Script to test:
npm run push
Coding Standards
- Write clean, readable, and well-documented code
- Follow TypeScript best practices
- Add appropriate JSDoc comments for new functions
- Maintain consistent code style with the existing codebase
- Write tests for new features
Pull Request Process
- Update the README.md with details of changes if needed
- Update the documentation if you're adding or changing functionality
- Ensure all tests pass
- Create a Pull Request with a clear title and description
Reporting Issues
- Use the GitHub issue tracker
- Provide a clear description of the issue
- Include steps to reproduce if applicable
- Mention your environment details
Questions or Suggestions?
Feel free to open an issue for discussion or reach out through GitHub.
5 months ago