Skip to main content

ReAct inspired Agent developed from scratch using Ollama. This agent uses task decomposition and uses provided tools.

Project description

MLUX-Reactly Agent Framework

A ReAct inspired Agent developed from scratch using Ollama. This agent uses task decomposition and uses provided tools.

Installation

A virtual environment is recommended:

python3 -m venv .venv
source .venv/bin/activate

From PIP

pip install mlux-reactly

From Source

pip install git+https://github.com/d-volution/mlux-reactly.git

Setting up Ollama

You also have to setup Ollama. See the README of Ollama for that.

The agent uses by default the Ollama model qwen2.5:7b-instruct-q8_0, but can be configured via the llm keyword argument. The demo RAG-tool included within this repository uses the embedding model nomic-embed-text.

ollama pull qwen2.5:7b-instruct-q8_0
ollama pull nomic-embed-text

Usage

from typing import Annotated
from mlux_reactly import ReactlyAgent, LLM

def count_substr(a: Annotated[str, "Some string"], b: Annotated[str, "substring to be counted"]) -> int:
    """This tool calculates how often string b occures in string a"""
    if not b:
        return 0
    return sum(1 for i in range(len(a) - len(b) + 1) if a[i:i+len(b)] == b)

agent = ReactlyAgent(tools=[count_substr], llm=LLM("qwen2.5:7b-instruct-q8_0"))

answer = agent.query("How many times does the letter l occure in 'artificial general intelligence'?")
print(f"agent answer: {answer}")

How to trace

Use LIVE_VERBOSE for printing the most important events live:

from mlux_reactly.tracer import TestTracer, LIVE_VERBOSE
# ...
agent = ReactlyAgent(tracer=TestTracer(live_format=LIVE_VERBOSE))

Or to print only toolruns and results without highlight colours live:

from mlux_reactly.tracer import TestTracer, FormatConfig
# ...
agent = ReactlyAgent(tracer=TestTracer(live_format=FormatConfig(show=['toolrun', 'result'], colored=False)))

These are the existing events:

key description
query an agent.query() call
task subtask the query is splitted into
stage a stage doing a LLM call with one specific prompt. If it fails, it might retry resulting in multiple LLM calls.
llmcall a single call of the LLM. Only shows up in trace if not in compact mode
toolrun The invocation of a user-supplied tool
root Root node of tracer
failed Some step/operation that failed
result The operation of the parent event finished with some result

When running from Git Repo

Local Install

pip install -r requirements.txt

Run simple chatbot

python3 test/chat.py

Evaluation

To evaluate the agent, you can use eval.py like this:

python3 test/eval.py -agents <agent names> -tests <test names with test params>

For example, use

python3 test/eval.py -agents reactly llama-react -tests hotpot/train:100:3

to run the 'hotpot' test with the examples from index 100 to 103 on both the Reactly and the Llama-ReAct agents.

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

mlux_reactly-0.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

mlux_reactly-0.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file mlux_reactly-0.2.tar.gz.

File metadata

  • Download URL: mlux_reactly-0.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mlux_reactly-0.2.tar.gz
Algorithm Hash digest
SHA256 6533c8408ec659d068930d9741c9db22001d92cf25af53e69490865241942aa8
MD5 ccaf64042b6c857088e72c2eb1820bf4
BLAKE2b-256 a7d89f7c7c974ccc2be099adb2a3a565416b1e133f1b9b260514b332e3edede3

See more details on using hashes here.

File details

Details for the file mlux_reactly-0.2-py3-none-any.whl.

File metadata

  • Download URL: mlux_reactly-0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mlux_reactly-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a2ad0e70f09546dbed097368bc5a7132119501639336a7e5c2bea539a015565
MD5 b32f51f9c972dc74941712361ea53b42
BLAKE2b-256 9a113091c2b3464606118df801c09f9678c7658277799b90543b07f6618fa63a

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