Skip to main content

Grasp Agents Library

Project description

Grasp Agents


Grasp Agents

PyPI version License: MIT PyPI downloads GitHub Stars GitHub Forks

Overview

Grasp Agents is a modular Python framework for building agentic AI pipelines and applications. It is meant to be minimalistic but functional, allowing for rapid experimentation while keeping full and granular low-level control over prompting, LLM handling, tool call loops, and inter-agent communication by avoiding excessive higher-level abstractions.

Features

  • Clean formulation of agents as generic entities over I/O schemas and shared context.
  • Transparent implementation of common agentic patterns:
    • Single-agent loops
    • Workflows (static communication topology), including loops
    • Agents-as-tools for task delegation
    • Freeform A2A communication via the in-process actor model
  • Built-in parallel processing with flexible retries and rate limiting.
  • Support for all popular API providers via LiteLLM.
  • Granular event streaming with separate events for LLM responses, thinking, and tool calls.
  • Callbacks via decorators or subclassing for straightforward customisation of agentic loops and context management.

Project Structure

  • processors/, llm_agent.py: Core processor and agent class implementations.
  • event_bus.py, runner.py: Communication management and orchestration.
  • llm_policy_executor.py: LLM actions and tool call loops.
  • prompt_builder.py: Tools for constructing prompts.
  • workflow/: Modules for defining and managing static agent workflows.
  • llm.py, cloud_llm.py: LLM integration and base LLM functionalities.
  • openai/: Modules specific to OpenAI API integration.
  • litellm/: Modules specific to LiteLLM integration.
  • memory.py, llm_agent_memory.py: Memory management.
  • run_context.py: Shared run context management.

Usage

Installation

Assuming your project manages dependencies through uv.

uv add grasp_agents
uv sync

You can of course also install using other managers like poetry or simply pip.

We recommend you use dotenv to automatically set enviroment variables from a .env file containting the necessary API keys, e.g.,

ANTHROPIC_API_KEY=your_anthropic_api_key

Try it out

Jupyter Notebook Example

Notebook Link

A Grasp-Agents Powered Web App

https://grasp.study/

Script Example

Create a script, e.g., problem_recommender.py:

import asyncio
from typing import Any

from dotenv import load_dotenv
from pydantic import BaseModel

from grasp_agents import BaseTool, LLMAgent, RunContext
from grasp_agents.litellm import LiteLLM, LiteLLMSettings
from grasp_agents.printer import print_event_stream
from grasp_agents.typing.events import ProcPacketOutEvent

load_dotenv()

sys_prompt = """
Your task is to suggest an exciting stats problem to the student. 
You should first ask the student about their education, interests, and preferences, then suggest a problem tailored specifically to them. 

# Instructions
* Use the provided tool to ask questions.
* Ask questions one by one.
* The problem must have all the necessary data.
* Use the final answer tool to provide the problem.
"""


class TeacherQuestion(BaseModel):
    question: str


StudentReply = str


ask_student_tool_description = """
"Ask the student a question and get their reply."

Args:
    question: str
        The question to ask the student.
Returns:
    reply: str
        The student's reply to the question.
"""


class AskStudentTool(BaseTool[TeacherQuestion, StudentReply, None]):
    name: str = "ask_student"
    description: str = ask_student_tool_description

    async def run(self, inp: TeacherQuestion, **kwargs: Any) -> StudentReply:
        return input(inp.question)


class Problem(BaseModel):
    problem: str


teacher = LLMAgent[None, Problem, None](
    name="teacher",
    llm=LiteLLM(
        model_name="claude-sonnet-4-5",
        llm_settings=LiteLLMSettings(reasoning_effort="low"),
    ),
    tools=[AskStudentTool()],
    final_answer_as_tool_call=True,
    sys_prompt=sys_prompt,
    stream_llm_responses=True,
)

async def main():
    ctx = RunContext[None]()
    async for event in print_event_stream(teacher.run_stream("start", ctx=ctx)):
        if isinstance(event, ProcPacketOutEvent):
            result = event.data.payloads[0]
            print(f"\n<Suggested Problem>:\n\n{result.problem}\n")

asyncio.run(main())

Run your script:

uv run problem_recommender.py

You can find more examples in src/grasp_agents/examples/notebooks/agents_demo.ipynb.

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

grasp_agents_legacy-0.6.50.tar.gz (66.1 kB view details)

Uploaded Source

Built Distribution

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

grasp_agents_legacy-0.6.50-py3-none-any.whl (97.7 kB view details)

Uploaded Python 3

File details

Details for the file grasp_agents_legacy-0.6.50.tar.gz.

File metadata

  • Download URL: grasp_agents_legacy-0.6.50.tar.gz
  • Upload date:
  • Size: 66.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for grasp_agents_legacy-0.6.50.tar.gz
Algorithm Hash digest
SHA256 521a518d23aa1e78e9d027f016004146c6f8918dc02cedd27645f121d94e9471
MD5 5568fecb9b0a5ed84feb189f334bbca1
BLAKE2b-256 c83db45d7f81b128ad98819795c426104ce9ef3ca74fd42d61ef0464c3f408d0

See more details on using hashes here.

File details

Details for the file grasp_agents_legacy-0.6.50-py3-none-any.whl.

File metadata

  • Download URL: grasp_agents_legacy-0.6.50-py3-none-any.whl
  • Upload date:
  • Size: 97.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for grasp_agents_legacy-0.6.50-py3-none-any.whl
Algorithm Hash digest
SHA256 ed91babd67f4c4d647f70250d6d64b17943ffdf9f8bd0e007446430148ad008c
MD5 c781e3ce76688bbf13416d36b50452c0
BLAKE2b-256 db50ede8b6ce3c08e1e1c8b9d04a5d4213de8bbd8dfcce6d4ef62b9c4fcaf9e8

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