Skip to content

Commit

Permalink
Merge pull request #5 from use-the-fork/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
use-the-fork authored Oct 22, 2024
2 parents b57c957 + 27fd68f commit 106d53b
Showing 1 changed file with 6 additions and 150 deletions.
156 changes: 6 additions & 150 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div align="center">

# 🧠 Synapse

![Build Status](https://github.com/use-the-fork/laravel-synapse/actions/workflows/tests.yml/badge.svg)
![Downloads](https://img.shields.io/packagist/dm/use-the-fork/synapse)

[Click here to read the documentation](https://use-the-fork.github.io/synapse/)

Expand All @@ -10,164 +13,17 @@ Synapse allows you to seamlessly integrate and manage AI agents in your Laravel

## Features

- Supports multiple AI integrations, including OpenAI and Claude.
- Supports multiple AI integrations, including OpenAI, Ollama and Claude.
- Easily extendable agent lifecycle with customizable hooks.
- Memory options for agents: temporary (CollectionMemory) or persistent (DatabaseMemory).
- Use Laravel's Blade system to create dynamic prompts.
- Build complex `few-shot` agent prompts with message tagging.
- Extend functionality by creating custom tools that can interact with agents. Tools can even make additional API calls or invoke other agents.
- Prebuilt agents available for quick and easy use with popular integrations like OpenAI.

## Installation

> **Requires [PHP 8.1+](https://php.net/releases/)**
1. Install via Composer:

```bash
composer require use-the-fork/synapse
```

1. Run the install command:

```bash
php artisan synapse:install
```

1. If you plan to use `DatabaseMemory`, ensure you publish the migrations by saying "yes" during installation.

## Configuration

1. Set up your `.env` file with the required API keys:

```dotenv
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
```

1. If packages are not autoloaded, add the service provider:

For **Laravel 10**:

```php
//config/app.php
'providers' => [
...
UseTheFork\Synapse\SynapseServiceProvider::class,
...
];
```

For **Laravel 11**:

```php
//bootstrap/providers.php
<?php
return [
App\Providers\AppServiceProvider::class,
UseTheFork\Synapse\SynapseServiceProvider::class,
];
```

## Usage

### Defining an Agent

Agents are the core of Synapse. To create an agent, extend the `Agent` class and define key methods like `resolveIntegration`, `resolveMemory`, and `$promptView`.

Example:

```php
<?php

use UseTheFork\Synapse\Agent;
use UseTheFork\Synapse\Integrations\OpenAIIntegration;
use UseTheFork\Synapse\Memory\CollectionMemory;
use UseTheFork\Synapse\Contracts\Agent\HasMemory;
use UseTheFork\Synapse\Contracts\Integration;
use UseTheFork\Synapse\Contracts\Memory;

class SimpleAgent extends Agent implements HasMemory
{
protected string $promptView = 'synapse::Prompts.SimplePrompt';

public function resolveIntegration(): Integration
{
return new OpenAIIntegration();
}

public function resolveMemory(): Memory
{
return new CollectionMemory();
}
}
```
## Getting Started

### Memory Options

Synapse offers two types of memory for agents:

- **CollectionMemory**: Temporary memory that exists only for the duration of the application's lifecycle.
- **DatabaseMemory**: Persistent memory stored in your database, allowing multiple agents to share or modify it.

To switch between these options, simply change the memory type in the `resolveMemory` method.

Example using `DatabaseMemory`:

```php
public function resolveMemory(): Memory
{
return new DatabaseMemory(123); // Use a specific memory ID
}
```

### Building Prompts

Use Laravel's Blade system to create agent prompts. Leverage the custom `<message>` tags to distinguish between user, system, and tool messages.

Example Blade prompt view:

```blade
<message role="user">
# Instruction
Write a welcome email for the following user:
## User Information
Name: {{$user->name}}
Favorite Color: {{$user->favorite_color}}
Favorite Emoji: {{$user->favorite_emoji}}
@include('synapse::Parts.OutputSchema')
</message>
```

## Integrations

Synapse supports the following integrations:

- **OpenAI**: Use the `OpenAIIntegration` class in your agents.
- **Claude**: Use the `ClaudeIntegration` class in your agents.

To configure these integrations, add the appropriate API key to your `.env` file and specify the integration in the `resolveIntegration` method.

Example:

```php
public function resolveIntegration(): Integration
{
return new OpenAIIntegration();
}
```

## Agent Lifecycle & Hooks

The Synapse agent lifecycle offers several points where you can hook in to modify the agent's behavior. These hooks allow for customizations such as adjusting input, memory, tools, and integration responses.

Refer to the full documentation for more details on available hooks and how to use them.

## Documentation

[Click here to read the documentation](https://use-the-fork.github.io/synapse/)
[Click here to get started](https://use-the-fork.github.io/synapse/)

## Support Synapse's Development

Expand Down

0 comments on commit 106d53b

Please sign in to comment.