### Installing AgentScript via npm Source: https://github.com/agentscript-ai/agentscript/blob/main/README.md This command installs the AgentScript SDK as a project dependency using the Node Package Manager (npm). ```shell npm install agentscript-ai ``` -------------------------------- ### Generated AgentScript Code Source: https://github.com/agentscript-ai/agentscript/blob/main/README.md This JavaScript code is an example of code generated by an LLM using AgentScript to find and summarize issues. The generated code calculates a date one week in the past, searches for issues created after that date, and then summarizes the retrieved issues to provide a progress update. The `result` variable stores the outcome of the agent. ```javascript // NOTE: this is real code generated by LLM. // it's not executed but parsed into AST and runs in a specialized runtime. // Calculate the date from 7 days ago const lastWeek = addToDate(new Date(), { days: -7 }); // Search for all issues created in the last week const issues = linear.searchIssues({ createdAfter: lastWeek, orderBy: 'createdAt', }); // Create a summary of the issues found result = summarizeData({ data: issues, prompt: 'Create a progress update focusing on number of tasks created, their current status distribution, and any notable patterns. Format as a clear business update.', }); ``` -------------------------------- ### Executing the Agent and Logging Output Source: https://github.com/agentscript-ai/agentscript/blob/main/README.md This TypeScript code shows how to execute an AgentScript agent and log its output and execution state. It calls `executeAgent` to run the agent, then logs the agent's output and the variables in the root execution context to the console. ```typescript await executeAgent({ agent }); // See the output console.log(agent.output); // Check variables in the execution state console.log(agent.root.variables); ``` -------------------------------- ### Defining an Agent with TypeScript Source: https://github.com/agentscript-ai/agentscript/blob/main/README.md This TypeScript code defines and executes an AI agent using the AgentScript SDK. It configures a language model, a Linear client, defines available tools including `addToDate`, `summarizeData`, and `searchIssues`, sets a task prompt, specifies the expected output type, and then generates and executes the agent. ```typescript import { executeAgent, inferAgent } from 'agentscript-ai'; import * as s from 'agentscript-ai/schema'; import { addToDate, summarizeData } from 'agentscript-ai/tools'; import { LinearClient, searchIssues } from '@agentscript-ai/linear'; import { anthropic } from '@ai-sdk/anthropic'; // Configure the language model const model = anthropic('claude-3-5-sonnet-latest'); // Configure the Linear client const linear = LinearClient({ apiKey: process.env.LINEAR_API_KEY, }); // Define available tools. const tools = { // Needed for date calculation addToDate, // Turns data into text summarizeData: summarizeData({ model }), // The real deal linear: { searchIssues: searchIssues({ model, 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 generate the AgentScript code const agent = await inferAgent({ tools, output, model, prompt, }); ``` -------------------------------- ### AgentScript Type Definitions Source: https://github.com/agentscript-ai/agentscript/blob/main/README.md This TypeScript code provides type definitions for the AgentScript environment, including the `Duration` type for time intervals, function signatures for `addToDate` and `summarizeData`, and the `linear` namespace with types for `Issue` and `searchIssues`. It also declares the global `result` variable where the agent's final output should be stored. ```typescript export type Duration = { years?: number; months?: number; days?: number; hours?: number; minutes?: number; seconds?: number; }; /** Add a duration to a date. */ export function addToDate(date: Date, duration: Duration): Date; export type SummarizeDataParams = { /** The data to summarize. Can be in any format. */ data: unknown; /** * The prompt to use to summarize the data. * Describe the expected outcome. */ prompt: string; }; /** Summarize any data */ export function summarizeData(params: SummarizeDataParams): string; declare namespace linear { export type Issue = { id: string; url: string; title: string; description?: string; status: string; createdAt: Date; updatedAt: Date; }; /** * Search for issues using a natural language query. * Do not filter results later, put all the search criteria in the query. * @param query - Descriptive query in object format. */ export function searchIssues(query: unknown): Issue[]; } /** You must put the result of the task here. */ let result: string; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.