A building block library for composed agent workflows
Project description
agenticblocks 🧱
A composable building block library for AI agent workflows. / Uma biblioteca componível para construir fluxos de agentes de IA.
🇺🇸 English
Philosophy
A library to build agent workflows like Lego blocks. Each step in your agentic pipeline is a self-contained block, with strictly typed inputs and outputs via Pydantic and natively concurrent execution using AsyncIO and NetworkX graphs.
- Strong typing: Pydantic validates connections and prevents unmatched dependencies between LLM tool calls.
- Standardized connections: Blocks only know their own inputs and outputs. Thus, entire workflows can act as single blocks later.
- Smart Parallelism (Waves): The asyncio engine fires simultaneous tasks (waves) whenever dependencies are resolved, maximizing API speed.
- Native Cycles: Declare bounded feedback loops directly in the graph (
add_cycle()). The executor handles iteration, feedback propagation, and exit conditions automatically. - Functions as Tools: Any plain Python function (sync or async) becomes a block with
@as_tool— no class boilerplate required.
Getting Started
Install the module locally for development:
pip install -e .
1. Define Input and Output Models
from pydantic import BaseModel
class HelloInput(BaseModel):
name: str
class HelloOutput(BaseModel):
greeting: str
2. Create the Logic Block
from agenticblocks.core.block import Block
class HelloWorldBlock(Block[HelloInput, HelloOutput]):
name: str = "say_hello"
async def run(self, input: HelloInput) -> HelloOutput:
msg = f"Hello, {input.name}! Welcome to agenticblocks."
return HelloOutput(greeting=msg)
3. Connect and Execute
import asyncio
from agenticblocks.core.graph import WorkflowGraph
from agenticblocks.runtime.executor import WorkflowExecutor
async def main():
graph = WorkflowGraph()
graph.add_block(HelloWorldBlock(name="say_hello"))
executor = WorkflowExecutor(graph)
ctx = await executor.run(initial_input={"name": "Alice"})
print(ctx.get_output("say_hello").greeting)
asyncio.run(main())
4. Functions as Tools
Any Python function can be registered as a block with @as_tool. Both sync and async functions are supported — sync functions run in a thread pool automatically.
from agenticblocks import as_tool
from agenticblocks.blocks.llm.agent import LLMAgentBlock
@as_tool
async def fetch_weather(city: str) -> str:
"""Returns the current weather for a city."""
return f"Sunny in {city}."
agent = LLMAgentBlock(
name="assistant",
model="gpt-4o-mini",
tools=[fetch_weather], # same interface as any Block
)
5. LLM Agent Autonomy & A2A
LLMAgentBlock is a ready-to-use orchestrator that dynamically translates your other Blocks into Tools (Agent-to-Agent) seamlessly.
- Bounded tool loop:
max_tool_callsprevents runaway loops. - A2A bridging: sub-agents are called as tools transparently — the parent LLM receives only the text response, not raw JSON metadata.
- Connection Pooling: Pass any
litellm_kwargs(HTTP clients, timeouts, etc.) to optimize API performance.
6. Native Feedback Cycles
Declare validator loops directly in the graph without any wrapper block:
from agenticblocks import as_tool
from agenticblocks.core.graph import WorkflowGraph
@as_tool
def validate_output(content: str) -> dict:
ok = len(content.split()) >= 100
return {"is_valid": ok, "feedback": "Too short." if not ok else ""}
graph = WorkflowGraph()
graph.add_block(writer)
graph.add_block(validate_output)
graph.add_cycle(
name="refine",
edges=[("writer", "validate_output")],
condition_block="validate_output",
max_iterations=3,
)
# Downstream nodes connect to the cycle output as a normal node
graph.connect("refine", "publisher")
The executor runs the cycle, propagates feedback to the producer on each rejection, and stores the result in ctx under the cycle name.
Examples & Model Recommendations
It is recommended to install Ollama with the model granite4:1b (ollama run granite4:1b) to test the examples locally. Alternatively, you can modify the examples to use a commercial API, such as Gemini (gemini/gemini-2.0-flash) or OpenAI.
| Example | Description |
|---|---|
01_hello_world.py |
Minimal block + graph + executor setup |
02_llm_pipeline.py |
Parallel wave execution with multiple blocks |
03_mcp_a2a_agent.py |
MCP bridge + Agent-to-Agent (A2A) tool delegation |
04_mcp_python_native.py |
Native Python MCP server |
05_basic_blocks.py |
Overhead benchmarking |
06_functionastool.py |
@as_tool decorator for plain functions |
07_validator_loop.py |
Native graph cycle with producer + validator feedback loop |
Note: Quantized or small models like
granitemay produce lower-quality reasoning. Large commercial models yield excellent results but require an API key environment variable. Free-tier rate limits may cause occasional errors; paid tiers offer stable operation.
🇧🇷 Português
Filosofia
Uma biblioteca para construir fluxos de agentes no estilo Lego. Cada passo do seu pipeline agêntico é um bloco auto-contido, com entradas e saídas rigorosamente tipadas via Pydantic e execução simultânea usando AsyncIO e grafos do NetworkX.
- Forte tipagem: Pydantic valida os encaixes e previne dependências não satisfeitas.
- Encaixes padronizados: Blocos só conhecem as próprias entradas e saídas. Workflows inteiros funcionam como blocos únicos.
- Paralelismo Inteligente (Ondas): O motor dispara tarefas simultâneas sempre que as dependências de um bloco são resolvidas.
- Ciclos Nativos: Declare loops de feedback diretamente no grafo com
add_cycle(). O executor gerencia iteração, propagação de feedback e condição de saída automaticamente. - Funções como Ferramentas: Qualquer função Python (síncrona ou async) vira um bloco com
@as_tool— sem boilerplate de classe.
Primeiros Passos
Instale o módulo de forma local editável:
pip install -e .
1–3. Blocos, Grafo e Execução
A estrutura básica é idêntica ao tutorial acima (seção em inglês): defina modelos Pydantic, crie um Block, adicione ao WorkflowGraph e execute com WorkflowExecutor.
4. Funções como Ferramentas
Qualquer função pode ser registrada como bloco com @as_tool. Funções síncronas rodam em thread pool automaticamente.
from agenticblocks import as_tool
@as_tool
def buscar_clima(cidade: str) -> str:
"""Retorna o clima atual de uma cidade."""
return f"Ensolarado em {cidade}."
5. Autonomia com Agentes LLM & A2A
O LLMAgentBlock abstrai e converte sub-blocos em ferramentas nativas (A2A). Destaques:
max_tool_calls: Limita o loop de ferramentas para evitar execuções infinitas.- A2A transparente: Agentes subordinados são chamados como ferramentas; o agente pai recebe apenas o texto da resposta, sem metadados JSON brutos.
- Connection Pooling: Aceite sessões HTTP e parâmetros estendidos via
litellm_kwargs.
6. Ciclos de Feedback Nativos
Declare um loop validador diretamente no grafo — sem bloco orquestrador especial:
from agenticblocks import as_tool
from agenticblocks.core.graph import WorkflowGraph
@as_tool
def validar(content: str) -> dict:
ok = len(content.split()) >= 100
return {"is_valid": ok, "feedback": "Muito curto." if not ok else ""}
graph = WorkflowGraph()
graph.add_block(escritor)
graph.add_block(validar)
graph.add_cycle(
name="refinar",
edges=[("escritor", "validar")],
condition_block="validar",
max_iterations=3,
)
graph.connect("refinar", "publicador")
O executor itera automaticamente, injeta o feedback no prompt do produtor a cada rejeição e disponibiliza o resultado final em ctx.get_output("refinar").
Exemplos & Modelos
Recomenda-se instalar o Ollama com o modelo granite4:1b para testar localmente. Alternativamente, use uma API comercial como Gemini ou OpenAI.
| Exemplo | Descrição |
|---|---|
01_hello_world.py |
Setup mínimo: bloco + grafo + executor |
02_llm_pipeline.py |
Execução paralela em waves |
03_mcp_a2a_agent.py |
Bridge MCP + delegação A2A entre agentes |
04_mcp_python_native.py |
Servidor MCP nativo em Python |
05_basic_blocks.py |
Benchmark de overhead |
06_functionastool.py |
Decorator @as_tool para funções simples |
07_validator_loop.py |
Ciclo nativo no grafo: produtor + validador com feedback |
Atenção: Modelos quantizados ou menores podem produzir resultados abaixo do esperado. Modelos comerciais grandes geram excelentes resultados, mas exigem configuração de API KEY e podem sofrer com limites da camada gratuita.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agenticblocks_io-0.8.3.tar.gz.
File metadata
- Download URL: agenticblocks_io-0.8.3.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbcc06957ccb66ad2cce0ffd32c442e9b39282aa6562c8a600c11daed0758c74
|
|
| MD5 |
62c37ef3c2198c95708d1845e7d37eae
|
|
| BLAKE2b-256 |
8e2cb1e3aa43584edfa389f4ab72e9c0b691b62c4b4e1f67fe72dec9ca0840c3
|
Provenance
The following attestation bundles were made for agenticblocks_io-0.8.3.tar.gz:
Publisher:
workflow.yml on gilzamir18/agenticblocks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agenticblocks_io-0.8.3.tar.gz -
Subject digest:
dbcc06957ccb66ad2cce0ffd32c442e9b39282aa6562c8a600c11daed0758c74 - Sigstore transparency entry: 1280058934
- Sigstore integration time:
-
Permalink:
gilzamir18/agenticblocks@4af86d8d1d5ae8b84482f4f993f950b952b44bf2 -
Branch / Tag:
refs/tags/v0.8.3 - Owner: https://github.com/gilzamir18
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@4af86d8d1d5ae8b84482f4f993f950b952b44bf2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file agenticblocks_io-0.8.3-py3-none-any.whl.
File metadata
- Download URL: agenticblocks_io-0.8.3-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
816def48135b06f5768d893dce774606f38c5e2a207d16b18975f2bc1addf076
|
|
| MD5 |
dfb49832f70e5b6c20bd81b7f68a3bae
|
|
| BLAKE2b-256 |
f0e5fda17090581809db13848b8d84fae14e220361ca5505eac955207d2ed6f1
|
Provenance
The following attestation bundles were made for agenticblocks_io-0.8.3-py3-none-any.whl:
Publisher:
workflow.yml on gilzamir18/agenticblocks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agenticblocks_io-0.8.3-py3-none-any.whl -
Subject digest:
816def48135b06f5768d893dce774606f38c5e2a207d16b18975f2bc1addf076 - Sigstore transparency entry: 1280058939
- Sigstore integration time:
-
Permalink:
gilzamir18/agenticblocks@4af86d8d1d5ae8b84482f4f993f950b952b44bf2 -
Branch / Tag:
refs/tags/v0.8.3 - Owner: https://github.com/gilzamir18
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@4af86d8d1d5ae8b84482f4f993f950b952b44bf2 -
Trigger Event:
release
-
Statement type: