Skip to main content

The tool is used for building and driving workflows specifically tailored for AI initiatives. It can be used to construct AI agents.

Project description

GitHub License PyPI - Version GitHub Workflow Status (with event) GitHub Workflow Status (with event) GitHub Workflow Status (with event) codecov Static Badge

Agere

Logo

Agere is a lightweight framework for building and driving AI agents or applications based on task flows. By defining specific jobs or handlers, Agere can automatically organize and execute complex task flows.

Installation

Agere has no third-party dependencies.

pip install agere

How to Use

Getting started
Guide

Architecture Overview

agere_architecture

Basic Concepts

TaskNode

Includes Commander, Job, and handler. Each TaskNode has one parent and 0-n children. These nodes form a tree structure, where each node determines its own task completion based on the status of all its child nodes.

Commander

Commander is responsible for organizing and scheduling task flows, managing an asynchronous Job queue. It is the top-level TaskNode.

Job

Job is a class, it is automatically scheduled by the Commander and managed in an asynchronous queue, ensuring sequentiality. Each Job has a task method, which wraps the actual task of the Job. Jobs can submit new Jobs or call handlers. You can think of it as submitting tasks to a superior.

handler

Handler is a method or function. Called directly by the caller without queue waiting, but it is still a part of the TaskNode system. A handler can submit new Jobs or call other handlers. You can think of it as delegating tasks to subordinates.

Callback

Callbacks can be added at various stages of a task, such as: task start, task completion, encountering exceptions, task termination, Commander ending, etc.

Example

For example, if you want to build an application where multiple AI roles participate in a group chat, it can be broken down into the following task units. (Assuming we call llm in a streaming manner to get replies. The reply object mentioned here refers to the iterable object obtained when calling llm, meaning that the information of an exchange is determined, but the actual generation and receipt of the information may not have started yet and needs to be completed in the subsequent iteration.)

  • GroupTalkManager (Job): This task is the first and the top-level parent node for all subsequent group chat tasks (except the Commander). All its child nodes can access this node through the node's ancestor_chain attribute, and it can be used to manage group chats. It stores a list (roles_list) containing all the roles participating in the group chat, and also needs an attribute (speaking) to indicate which role is currently speaking. You can also add some methods to it, such as create_role, to add new chat roles, and close_group_talk, to close the group chat.
  • TalkToAll (Job): Retrieves the list of roles from GroupTalkManager, sends the message to each role, collects all the reply objects in a dictionary, then sets the GroupTalkManager's speaking attribute to None, and passes the reply dictionary to (calls) handle_response.
  • handle_response (handler): This handler processes each reply in the reply dictionary by calling a parse_stream_response, where multiple parse_stream_responses start executing concurrently.
  • parse_stream_response (handler): Responsible for actually collecting and processing reply information. There are two scenarios:
    • The role has nothing to say, no need to process.
    • The role has something to say, then checks with GroupTalkManager whether someone is currently speaking. If someone is speaking, it denies the role's request and informs them who is speaking. If no one is speaking, it allows the role's request, changes the GroupTalkManager's speaking attribute to that role, and finally submits the role's reply object as a new TalkToAll Job.

This application uses a preemptive chat method, as opposed to a turn-based multi-round dialogue mechanism, to mimic real-life multi-person chat scenarios. By breaking down the complex task into two Jobs and two handlers, the Commander can automatically organize and execute the task. In this way, you only need to focus on what to do next, without needing to plan globally, effectively reducing the difficulty of building complex processes. The specific implementation of this process can be referred to in the example code: openai_group_talk.

License

This project is licensed under the MIT License.

Note: This library is migrated from the commander in gptui's kernel.

Project details


Download files

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

Source Distribution

agere-0.2.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

agere-0.2.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file agere-0.2.0.tar.gz.

File metadata

  • Download URL: agere-0.2.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for agere-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bd992adf1b398833c8f11404ea7314552ad2a7483266bc4c6f4857a24a3d3e4e
MD5 7f192fc235dff525c7b6b9d4eeac2247
BLAKE2b-256 e6d0b12f63d0447e737b8bd6b993d93ef0c3ec5984469dfcea7de69bc940bf32

See more details on using hashes here.

File details

Details for the file agere-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: agere-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for agere-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95b320b448f29ae3ac0a0cbbf8e3a3b1b163718cd254fd78b042da32372e3741
MD5 d326751fd4965f9f630fad5639b40234
BLAKE2b-256 12ea2a089c01090b374db17416e888b97caa583ac3738d9466c42d3b8c65dbc6

See more details on using hashes here.

Supported by

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