Skip to content

Agents API

The agent() function creates an agent builder for defining your bot's personality and behavior.

Basic Usage

typescript
import { agent } from "@andresaya/flowkit";

const myAgent = agent("Alex")
  .company("TechCorp")
  .personality("friendly and helpful")
  .language("en")
  .build();

API Reference

agent(name: string)

Creates a new agent builder.

Parameters:

  • name - The agent's name (used in introductions)

Returns: AgentBuilder


AgentBuilder Methods

.company(name: string)

Sets the company/organization the agent represents.

typescript
agent("Alex").company("ACME Corp")

.personality(description: string)

Describes the agent's personality traits.

typescript
agent("Alex").personality("friendly, professional, and patient")

.language(lang: string)

Sets the agent's primary language.

typescript
agent("Alex").language("Spanish")
agent("Alex").language("en") // Also accepts codes

.context(text: string)

Adds additional context or instructions for the agent.

typescript
agent("Alex").context(`
  You are a customer support specialist.
  Always verify the customer's account before providing information.
  Never discuss competitor products.
`)

.restrict(...restrictions: string[])

Adds behavioral restrictions.

typescript
agent("Alex").restrict(
  "Never discuss pricing",
  "Do not provide legal advice",
  "Always escalate complaints"
)

.strict()

Enables strict mode - the LLM will follow the script exactly.

typescript
agent("Alex").strict()

.systemPrompt(prompt: string)

Adds a custom system prompt prefix.

typescript
agent("Alex").systemPrompt("Always start responses with the user's name.")

.build()

Builds and returns the final AgentConfig object.

typescript
const config = agent("Alex")
  .company("TechCorp")
  .build(); // Returns AgentConfig

AgentConfig Type

typescript
interface AgentConfig {
  name: string;
  company?: string;
  personality?: string;
  language?: string;
  context?: string;
  restrictions?: string[];
  mode?: "flexible" | "strict";
  systemPrompt?: string;
}

Examples

Basic Agent

typescript
const basic = agent("Support Bot").build();

Full Configuration

typescript
const enterprise = agent("Enterprise Assistant")
  .company("Fortune 500 Corp")
  .personality("professional, knowledgeable, and efficient")
  .language("English")
  .context(`
    You handle enterprise support tickets.
    Always ask for ticket number first.
    Prioritize security and compliance.
  `)
  .restrict(
    "Never share internal documentation",
    "Do not discuss unreleased features"
  )
  .strict()
  .build();

Multilingual Agent

typescript
const spanish = agent("Carlos")
  .company("Claro Colombia")
  .language("Spanish")
  .personality("amable y profesional")
  .strict()
  .build();

Best Practices

Name Selection

Choose names that match your brand voice. "Alex" feels friendly, "Enterprise Assistant" feels professional.

Personality

Be specific about personality traits. Instead of "nice", say "friendly, patient, and empathetic".

Context

Use context for domain-specific knowledge that the base LLM might not have.

Strict Mode

Use strict mode when exact wording matters (compliance, legal, financial flows).

Released under the MIT License.