Skip to content

Agents

An Agent defines your AI assistant's identity, personality, and behavior.

Creating an Agent

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

const myAgent = agent("Alex")
  .company("TechCorp")
  .personality("friendly, professional, concise")
  .language("en")
  .restrict("never discuss pricing")
  .restrict("never make promises")
  .context("We are a B2B SaaS company")
  .strict()  // Optional: enable strict mode
  .build();

Agent Properties

name (required)

The agent's name. Used in system prompts and can be referenced in messages.

typescript
agent("Marcela")  // Agent will introduce itself as Marcela
agent("Support Bot")  // More generic name

.company(name)

The company or brand the agent represents.

typescript
agent("Alex").company("ACME Corp")
// "You are Alex, the virtual assistant for ACME Corp"

.personality(traits)

Personality traits that influence how the agent communicates.

typescript
.personality("friendly, helpful, uses emojis")
.personality("professional, formal, concise")
.personality("casual, humorous, uses slang")

.language(code)

Force a specific language for all responses. If not set, the agent will respond in the user's language.

typescript
.language("en")  // Always English
.language("es")  // Always Spanish
.language("pt")  // Always Portuguese
// Omit for auto-detection

Supported codes: en, es, pt, fr, de, it, or any ISO 639-1 code.

.restrict(rule)

Things the agent must NEVER do. Can be called multiple times.

typescript
agent("Sales Bot")
  .restrict("never discuss competitor products")
  .restrict("never give exact prices, always say 'contact sales'")
  .restrict("never make delivery promises")
  .restrict("never share internal policies")

.context(info)

Additional context about your business, product, or situation.

typescript
.context(`
  We sell enterprise software for HR departments.
  Our main products are: PayrollPro, HireHub, and TimeTrack.
  Support hours are 9am-6pm EST Monday-Friday.
`)

.strict()

Enable strict mode. The agent will follow the flow exactly as defined, using the exact messages from each step.

typescript
// Flexible mode (default)
agent("Alex").build();

// Strict mode - follows script exactly
agent("Alex").strict().build();

See Modes for detailed comparison.

.systemPrompt(prompt)

Advanced: Add a custom system prompt that will be prepended to the generated one.

typescript
.systemPrompt(`
  You have access to our knowledge base.
  Always check KB before saying "I don't know".
`)

Complete Example

typescript
const enterpriseAgent = agent("Enterprise Assistant")
  .company("GlobalCorp")
  .personality("professional, knowledgeable, patient")
  .language("en")
  .restrict("never share customer data")
  .restrict("never discuss internal processes")
  .restrict("never make commitments without approval")
  .context(`
    GlobalCorp is a Fortune 500 company.
    We provide cloud infrastructure services.
    Our SLA guarantees 99.99% uptime.
  `)
  .strict()
  .build();

Agent in Flows

The agent configuration is passed to the flow:

typescript
const myFlow = flow("support", myAgent)
  .ask("greeting", "Hello! How can I help?", text(), "query")
  .done()
  .build();

Tips

  1. Be specific with personality - "friendly and professional" is better than just "nice"

  2. Use restrictions wisely - Only add restrictions that matter. Too many can confuse the LLM.

  3. Language setting - Only force a language if you're sure about your users. Auto-detection is powerful.

  4. Context length - Keep context concise. The LLM has limited attention.

  5. Strict mode - Use for compliance-critical flows (customer service scripts, surveys, legal).

Released under the MIT License.