Skip to main content

An agent framework for the age of agents

Project description

Flock by white duck

Declarative LLM Orchestration at Scale

Traditional Agent Frameworks ๐Ÿ™ƒ Flock ๐Ÿค๐Ÿง๐Ÿ“ ๐Ÿฆ†
๐Ÿค– Interaction Design ๐Ÿ“ Simplified Agent Logic
โ€ข Requires complex prompt tuning โ€ข Straightforward input/output definitions
โ€ข Fragile and hard-to-maintain โ€ข No need for prompt engineering
โ€ข Time-consuming adjustments โ€ข Focused on business logic
๐Ÿ’ฅ Reliability Challenges โšก Robust & Scalable
โ€ข Prone to single points of failure โ€ข Built-in fault tolerance
โ€ข Lacks automatic recovery โ€ข Automated retries & error handling
โ€ข Difficult to monitor โ€ข Full observability & logging
๐Ÿ—๏ธ Execution Constraints ๐Ÿ”„ Flexible Orchestration
โ€ข Linear workflows, limited adaptability โ€ข Dynamic and modular execution
โ€ข Lacks parallelism & batching โ€ข Supports concurrency & batch processing
โ€ข Struggles with scaling โ€ข Persistent state management

Hello, Bot

MODEL = "openai/gpt-4o"

async def main():
 
    #--------------------------------
    # Create the flock
    #--------------------------------
    # The flock is the place where all the agents are at home
    flock = Flock(model=MODEL)

    #--------------------------------
    # Create an agent
    #--------------------------------
    # The flock doesn't believe in prompts (continue reading for more info)
    # The flock just declares what agents get in and what agents produce
    # bloggy takes in a blog_idea and outputs a funny_blog_title and blog_headers
    bloggy = Flock(
        DeclarativeAgent,
        name="bloggy",
        input="blog_idea",
        output="funny_blog_title, blog_headers"  
    )

    #--------------------------------
    # Let the flock do its thing
    #--------------------------------
    # By giving the flock a start_agent and an input, we can run the flock
    # local_debug makes it easier to debug the flock
    result = await flock.run_async(
        context=context,
        start_agent=bloggy,
        input="a blog about cats",
        local_debug=True
    )
    # earn the fruits of the flock's labor
    print(result)


    # Continue reading to give your flock temporal(ly) super powers, heh.

Problems with other agent frameworks

  • Instead of writing software you need to write pages long natural language prompts
  • One crash and your whole agent system is dead
  • Demand having your system be a real DAG and a real state machine

How flock tries to solve it:

  • Just declare what your agents get ind, and what they should return
  • First grade temporalio support. Retry, Error, Timeout etc etc are somethi
  • Chain your agents together in any kind you want

Philosophy & Design Principles

Say goodbye to prompting

Sometimes you see agents with a 200 lines of text system prompt. How do evaluate if this is the most optimal prompt for your use case? How would changes affect the performance? Questions for there is no easy answer.

How does a good prompt look like? What happens with your prompt if you switch models?

With flock you just tell an agent what kind of input it gets, and what it should output. Done. Easy peasy.

The philosophy behind this approach is simple: by focusing on the interface (inputs and outputs) rather than implementation details (prompts), we create more maintainable and adaptable systems. This declarative approach means:

  • Your agents are model-agnostic
  • Behavior can be tested and validated objectively
  • Changes are localized and predictable
  • Integration with other systems becomes straightforward

Testable

Reducing the need for fuzzy natural language to a minimum agents become easily testable, evaluable. flock comes with tools to know exactly how good your agents and therefore the agent system is performing.

This focus on testability isn't just about catching bugs - it's about building confidence in your AI systems:

  • Clear input/output contracts make unit testing straightforward
  • Type safety ensures data consistency
  • Performance metrics are built into the framework
  • Behavior can be validated systematically

Production ready

Would you run your agent system in critical environments? The answer is probably no, since with most frameworks one dead endpoint or uncatched exception will break the whole agent system.

flock uses Temporal as its workflow engine which comes with battle-hardened retry, failure, exception options.

This production-readiness is achieved through several key design decisions:

  • Temporal workflow engine for durability and reliability
  • Strong typing for predictable behavior
  • Modular architecture for maintainability
  • Built-in monitoring and debugging capabilities

Core Features

  • Declarative Agent System: Define agents with clear input/output specifications and optional tool capabilities
  • Temporal Workflow Integration: Built-in support for durable execution and state management using Temporal
  • Tool Integration: Easy integration of external tools like web search, code evaluation, and math computation
  • Type Safety: Strong typing support for agent inputs and outputs
  • DSPy Integration: Seamless integration with DSPy for LLM interactions
  • Flexible Architecture: Support for agent chaining, hand-offs, and complex workflows

Architecture and Flow

alt text

alt text

Requirements

Nothing. Temporal is not needed for development but recommended

Either clone https://github.com/temporalio/docker-compose and up the compose

or install the temporal cli

https://docs.temporal.io/cli

Installation

pip install flock

Quick Start

Here's a simple example of creating and using an agent:

import asyncio
from flock.core.agents.declarative_agent import DeclarativeAgent
from flock.core.flock import flock

async def main():
    # Initialize flock
    agent_runner = flock()

    # Create a simple agent
    agent = DeclarativeAgent(
        name="blog_title_agent",
        input="blog_idea",
        output="funny_blog_title",
    )
    agent_runner.add_agent(agent)

    # Run the agent
    result = await agent_runner.run_async(
        start_agent=agent,
        input="a blog about cats",
        local_debug=True,
    )
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

Web Application

alt text

flock comes with a built-in web interface for managing and monitoring your agents. The web app provides a rich, interactive environment for working with your agent systems.

TODO: Expand

Running the Web App

# After installing flock
flock
# Or with uv
uv run flock

Features

  • Dashboard: Overview of your agent systems and their status
  • Agent Management:
    • List and filter agents
    • View agent details and configuration
    • Monitor production readiness
    • Track agent history
  • Agent Systems: Manage complex agent workflows and interactions
  • History: View execution history and results
  • Tools: Access and manage available tools
  • Playground: Interactive environment for testing agents
  • Settings: Configure system preferences and integrations

Technical Details

The web application is built with:

  • FastHTML for UI components
  • MonsterUI for enhanced UI elements
  • Interactive features using D3.js and interact.js
  • Real-time updates and monitoring
  • Responsive design for different screen sizes

Interface Structure

Web Interface
โ”œโ”€โ”€ Sidebar Navigation
โ”‚   โ”œโ”€โ”€ Dashboard
โ”‚   โ”œโ”€โ”€ Agents
โ”‚   โ”œโ”€โ”€ Agent Systems
โ”‚   โ”œโ”€โ”€ History
โ”‚   โ”œโ”€โ”€ Tools
โ”‚   โ”œโ”€โ”€ Playground
โ”‚   โ””โ”€โ”€ Settings
โ”œโ”€โ”€ Main Content Area
โ”‚   โ”œโ”€โ”€ Agent List
โ”‚   โ””โ”€โ”€ Agent Details
โ””โ”€โ”€ Interactive Features
    โ”œโ”€โ”€ Theme Switching
    โ”œโ”€โ”€ Search Functionality
    โ””โ”€โ”€ Real-time Updates

Advanced Usage

Agents with Tools

Agents can use tools to interact with external systems:

from flock.core.tools import basic_tools

agent = DeclarativeAgent(
    name="research_agent",
    input="research_topic",
    output="research_result",
    tools=[basic_tools.web_search_tavily],
)

Type-Safe Outputs

Define complex output types for structured responses:

agent = DeclarativeAgent(
    name="analysis_agent",
    input="long_text",
    output="""
        title: str,
        headings: list[str],
        entities_and_metadata: list[dict[str, str]],
        type: Literal['news', 'blog', 'opinion piece', 'tweet']
    """,
)

Agent Chaining

Create chains of agents that can hand off tasks:

# First agent in chain
project_plan_agent = DeclarativeAgent(
    name="project_plan_agent",
    input="project_idea",
    output="catchy_project_name, project_pitch, project_plan_headings: list[str]",
    tools=[basic_tools.web_search_tavily, basic_tools.code_eval],
)

# Second agent in chain
content_agent = DeclarativeAgent(
    name="content_agent",
    input="context,project_plan_agent.project_plan_headings.items",
    output="project_plan_heading, project_plan_content_for_heading",
)

# Set up hand-off
project_plan_agent.hand_off = content_agent

Core Components

flock Class

The main orchestrator that manages agent creation and execution:

  • Handles agent registration
  • Manages workflow execution
  • Supports both local debugging and distributed execution

DeclarativeAgent

Base class for creating agents with:

  • Input/output specifications
  • Tool integration
  • Type validation
  • Hand-off capabilities

Workflow System

Built on Temporal for:

  • Durable execution
  • State management
  • Error handling
  • Activity tracking

Tools

Built-in tools include:

  • Web search (via Tavily)
  • Math evaluation
  • Code execution
  • Extensible tool system for custom integrations

Architecture

flock Framework
โ”œโ”€โ”€ Core
โ”‚   โ”œโ”€โ”€ Agents
โ”‚   โ”‚   โ”œโ”€โ”€ DeclarativeAgent
โ”‚   โ”‚   โ””โ”€โ”€ Agent Registry
โ”‚   โ”œโ”€โ”€ Tools
โ”‚   โ”‚   โ””โ”€โ”€ Basic Tools
โ”‚   โ””โ”€โ”€ flock Manager
โ”œโ”€โ”€ Workflow
โ”‚   โ”œโ”€โ”€ Activities
โ”‚   โ”œโ”€โ”€ Temporal Setup
โ”‚   โ””โ”€โ”€ Workflow Definitions
โ””โ”€โ”€ App
    โ””โ”€โ”€ Components

Development

Prerequisites

  • Python 3.12+
  • Temporal server running locally (for workflow features)
  • Required API keys (e.g., Tavily for web search)

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/flock.git
cd flock
  1. Create a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -e .

Running Tests

pytest tests/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the terms of the LICENSE file included in the repository.

Acknowledgments

  • Built with DSPy
  • Uses Temporal for workflow management
  • Integrates with Tavily for web search capabilities
  • Web interface built with FastHTML and MonsterUI

Evolution & Future Direction

flock was born from the realization that current agent frameworks often prioritize flexibility at the cost of reliability and maintainability. The framework's design decisions reflect this focus:

Why Declarative?

The declarative approach wasn't just a stylistic choice - it was a deliberate decision to separate what agents do from how they do it. This separation means:

  • Agents can be optimized independently of their interface
  • Different LLM backends can be swapped without changing agent definitions
  • Testing and validation become straightforward
  • Integration with existing systems is simplified

Why Temporal?

Using Temporal as the workflow engine was crucial for production reliability:

  • Automatic retry on failures
  • Built-in state management
  • Scalable execution
  • Detailed execution history
  • Production-grade monitoring

Future Plans

The framework is actively evolving with several key areas of focus:

  • Enhanced type system for more complex agent interactions
  • Expanded tool ecosystem
  • Improved optimization capabilities
  • Advanced monitoring and debugging features
  • Extended testing and validation tools

Join us in building the future of reliable, production-ready AI agent systems!

Project details


Release history Release notifications | RSS feed

This version

0.1.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flock_core-0.1.2.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flock_core-0.1.2-py3-none-any.whl (63.8 kB view details)

Uploaded Python 3

File details

Details for the file flock_core-0.1.2.tar.gz.

File metadata

  • Download URL: flock_core-0.1.2.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for flock_core-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8018115d4745d675e10023243711015edc968a60c367ab947be110ed19cd3a1e
MD5 9200854b66fd9566f4830c1e53d59761
BLAKE2b-256 f460edeacdb6f4d1cb3835877a2ba9e8312f91e41ac339fcb634719e88961184

See more details on using hashes here.

File details

Details for the file flock_core-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: flock_core-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 63.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for flock_core-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f5a6c37c43df675fe805f7cee4110fcda4f854a48ab7a44d5ffce3b398139544
MD5 83d8be33e316c2e733970092fb202fd9
BLAKE2b-256 476908f41dc1987c1b455356fdf1def5a28e1c1dac149606b59e34ca026adf41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page