Linear Example
This example demonstrates how to use AgentScript with the Linear API to query issues based on a user prompt.
Overview
This example showcases:
- Using the
LinearClient
to interact with Linear - Using the
searchIssues
tool to query issues based on a user prompt - Using
addToDate
andsummarizeData
tools - A complete agent workflow, from code generation to execution
Setup
- Install dependencies:
yarn
- Create
.env
file:
ANTHROPIC_API_KEY=your-anthropic-api-key
LINEAR_API_KEY=your-linear-api-key
- Run the example:
yarn start
Implementation
import chalk from 'chalk';
import { LinearClient, searchIssues } from '@agentscript-ai/linear';
import { executeAgent, inferAgent } from 'agentscript-ai';
import { AnthropicModel } from 'agentscript-ai/anthropic';
import * as s from 'agentscript-ai/schema';
import { addToDate, summarizeData } from 'agentscript-ai/tools';
// Configure the language model
const llm = AnthropicModel({
model: 'claude-3-5-sonnet-latest',
apiKey: process.env.ANTHROPIC_API_KEY,
maxTokens: 1024,
});
// Configure the Linear client
const linear = LinearClient({
apiKey: process.env.LINEAR_API_KEY,
});
// Define available tools
const tools = {
addToDate,
summarizeData: summarizeData({ llm }),
linear: {
searchIssues: searchIssues({ llm, linear }),
},
};
// Define a task for the agent
const prompt = 'Give me a progress update of tasks created in the last week';
// Define the expected output
const output = s.string();
// Let the LLM infer the agent based on the prompt and runtime
const agent = await inferAgent({
tools,
output,
llm,
prompt,
});
// Execute the agent
await executeAgent({ agent });
// Log the results
console.log(chalk.green('Agent output:'));
console.log(agent.output);
Key Features
- API Integration: Shows how to use external APIs with AgentScript
- Tool Composition: Demonstrates combining different tools for complex tasks
- Code Generation: Highlights AgentScript's ability to generate code for external services
- Environment Setup: Shows proper configuration of API keys and dependencies
- Error Handling: Demonstrates best practices for handling API responses