Copyright (c) 2024 Continual, Inc. All rights reserved.

# Continual SDK

This package contains the Continual SDK.

## Usage

To use the SDK, install it using your preferred package manager:

```bash
pnpm install @continual/sdk
```

To run the SDK, use the `continual` command:

```bash
npx continual --help
```

To create a custom agent, use the `createStandardSubAgent` function in a file like
`agents/my-agent.ts`:

```typescript
/**
 * A simple agent that allows you to chat with an LLM.
 *
 */

import { createContinualOpenAiModel, createStandardSubAgent } from "@continual/sdk";

export const llmAgent = createStandardSubAgent({
  model: createContinualOpenAiModel({ model: "gpt-4o" }),
  instructions: "you are a helpful agent.",
  tools: {},
});
```

Create a file that will register this agent in `webapps.ts`:

```typescript
#!/usr/bin/env tsx
import { webserver } from "@continual/sdk";

import { llmAgent } from "./agents/my-agent";

webserver({
  agents: {
    llmAgent: {
      agent: llmAgent,
      chatGreetingMessage: "Hello, how can I help you today?",
      enableClientComponents: true,
    },
  },
});
```

Before you run this, you need to set up the following environment variables. By default, the SDK
will try to read these from your environment variables file in the `.env` file in your project root.

- `CONTINUAL_API_KEY`: Your Continual API key.
- `CONTINUAL_API_URL`: The URL of the Continual service. By default this is
  `https://console.continual.ai/api`.
- `CONTINUAL_SERVICE_URI`: The URL of this service. This needs to be a URL that the Continual
  service can reach this service at. For deployment to production this needs to be a public URL. For
  development, you can use `ngrok` to create a public URL.

NOTE: by default, when running/deploying it will try to execute the following command:

```bash
pnpm dlx tsx webapps.ts
```

If you want to use a different command to run your service, you can set the `EXECUTION_COMMAND` in
your `.env` file. You can also set this in the `deploy` command. To run the service, use the command
line:

```bash
npx continual deploy -n my-custom-agent
```

This will package up your local directory (see additional options for the deploy command as well)
and deploy to a managed environment.

If you want to run this locally (or in any other environment), you can use the command:

```bash
npx continual deploy -u -n my-custom-agent
```

Additionally if you want to not deploy the application but just the agent, you can use the command:

```bash
pnpm dlx tsx ts-node ./webapps.ts
```
