Linear Integration

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 and summarizeData tools
  • A complete agent workflow, from code generation to execution

Setup

  1. Install dependencies:
yarn
  1. Create .env file:
ANTHROPIC_API_KEY=your-anthropic-api-key
LINEAR_API_KEY=your-linear-api-key
  1. 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

  1. API Integration: Shows how to use external APIs with AgentScript
  2. Tool Composition: Demonstrates combining different tools for complex tasks
  3. Code Generation: Highlights AgentScript's ability to generate code for external services
  4. Environment Setup: Shows proper configuration of API keys and dependencies
  5. Error Handling: Demonstrates best practices for handling API responses