Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: readme #32

Merged
merged 3 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 79 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
# dead-simple-ai-agent
# Dead Simple AI Agent

A lightweight, functional, and composable framework for building AI agents that work together to solve complex tasks. Built with TypeScript and designed to be serverless-ready.

## Why Another AI Agent Framework?

Most existing AI agent frameworks are either too complex, heavily object-oriented, or tightly coupled to specific infrastructure. We wanted something different - a framework that embraces functional programming principles, remains stateless, and stays laser-focused on composability.

The framework is designed around the idea that AI agents should be:
- Easy to create and compose
- Infrastructure-agnostic
- Stateless by default
- Minimal in dependencies
- Focused on team collaboration

## Core Concepts

### Agents

Agents are specialized workers with specific roles and capabilities. Each agent has:
- A defined role
- A clear description of capabilities
- Optional tools they can use
- A configured language model provider

### Tools

Tools extend agent capabilities by providing concrete actions they can perform. Tools are pure functions with:
- A description
- Typed parameters (using Zod)
- An execute function

### Workflows

Workflows define how agents collaborate to achieve a goal. They specify:
- Team members
- Task description
- Expected output
- Optional configuration

### Iteration

The framework provides two main ways to orchestrate agent collaboration:

#### Teamwork

The `teamwork` function handles complete workflow execution from start to finish, managing the entire process automatically. It's perfect for simple use cases where you want to get results in a single call.

```typescript
// This will block until the workflow is complete
const result = await teamwork(workflow)
```

#### Iterate

The `iterate` function provides a stateless, step-by-step execution model. Each call returns the new state without maintaining any internal state.

```typescript
// Initialize, or get from storage
const initialState = workflowState(workflow)

// Iterate over the workflow
const newState = await iterate(workflow, initialState)

// Check status
console.log(newState.status)
```

This approach offers several benefits:

- **Pausable Execution**: Stop and resume workflow execution at any point
- **State Persistence**: Save the state between iterations to your preferred storage
- **Progress Monitoring**: Inspect the workflow state after each iteration
- **Error Recovery**: Handle failures gracefully by retrying from the last successful state
- **Custom Control Flow**: Implement your own execution patterns and recovery strategies

This functional approach makes the framework particularly well-suited for building long-running workflows that are distributed across multiple servers in the cloud.


15 changes: 15 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Examples
====

Each example is a self-contained TypeScript file that can be run with Bun, or with `tsx`

```bash
$ bun run example/<example-name>.ts
```

or

```bash
$ tsx example/<example-name>.ts
```

7 changes: 7 additions & 0 deletions example/src/medical_survey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { teamwork } from '@dead-simple-ai-agent/framework/teamwork'

import { preVisitNoteWorkflow } from './medical_survey_stateless.js'

const result = await teamwork(preVisitNoteWorkflow)

console.log(result)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Example borrowed from CrewAI.
*/

import { agent } from '@dead-simple-ai-agent/framework/agent'
import { iterate } from '@dead-simple-ai-agent/framework/teamwork'
import { tool } from '@dead-simple-ai-agent/framework/tool'
Expand All @@ -10,7 +11,7 @@ import { tmpdir } from 'os'
import { join } from 'path'
import { z } from 'zod'

import { lookupWikipedia } from './tools.js'
import { lookupWikipedia } from '../tools.js'

async function requestUserInput(prompt: string): Promise<string> {
return new Promise((resolve) => {
Expand All @@ -20,7 +21,8 @@ async function requestUserInput(prompt: string): Promise<string> {
})
})
}
export const askPatient = tool({

const askPatient = tool({
description: 'Tool for asking patient a question',
parameters: z.object({
query: z.string().describe('The question to ask the patient'),
Expand Down Expand Up @@ -56,7 +58,7 @@ const reporter = agent({
},
})

const preVisitNoteWorkflow = workflow({
export const preVisitNoteWorkflow = workflow({
members: [nurse, reporter],
description: `
Create a pre-visit note for a patient that is about to come for a visit.
Expand Down
3 changes: 2 additions & 1 deletion example/src/surprise_trip.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* Example borrowed from CrewAI.
*/

import { agent } from '@dead-simple-ai-agent/framework/agent'
import { teamwork } from '@dead-simple-ai-agent/framework/teamwork'
import { workflow } from '@dead-simple-ai-agent/framework/workflow'

import { lookupWikipedia } from './tools.js'
import { lookupWikipedia } from '../tools.js'

const personalizedActivityPlanner = agent({
role: 'Activity Planner',
Expand Down