Hugging Face Transformers integration for the Agent Design Pattern framework.
aap_transformers provides Hugging Face Transformers-specific implementations of the core agent abstractions defined in aap_core. It enables you to run open-weight LLMs locally (or on cloud GPUs) within the agent orchestration framework, supporting causal language models with system prompts, user templates, and multi-turn conversations — all without relying on external API providers.
pip install aap_transformersfrom aap_transformers.chain import ChatCausalMultiTurnsChain
chain = ChatCausalMultiTurnsChain(
model="HuggingFaceTB/SmolLM3-3B",
system_prompt="You are a helpful assistant.",
user_prompt_template="{query}",
device="cuda",
max_new_tokens=2048,
)ChatCausalMultiTurnsChain: A Transformers-backed multi-turn chain that extendsBaseCausalMultiTurnsChainfromaap_core. Supports system prompts, user templates, device placement (CPU/CUDA), and configurable generation parameters.- Local model inference: Run open-weight models directly via the
transformerslibrary — no external API keys or cloud services required. - GPU acceleration: Native support for CUDA devices and
accelerate-based model loading for efficient inference. - Token usage tracking: Integrates with
aap_core'sTokenUsagetype for consistent tracking across agents.
aap_transformers depends on aap_core. Install both together:
pip install aap_core aap_transformers# Weaviate integration
pip install "aap_transformers[weaviate]"uv sync --group devfrom a2a.types import AgentCard, AgentSkill, AgentCapabilities
from aap_core.agent import BaseAgent
from aap_core.types import AgentMessage
from aap_transformers.chain import ChatCausalMultiTurnsChain
class MyAgent(BaseAgent):
chain: BaseLLMChain
def execute(self, message: AgentMessage, **kwargs) -> AgentMessage:
self.state = "running"
message = self.chain.invoke(message, **kwargs)
message.execution_result = "success"
message.origin = self.card.name
self.state = "idle"
return message
chain = ChatCausalMultiTurnsChain(
model="ibm-granite/granite-4.0-h-1b",
system_prompt="You are a helpful coding assistant.",
user_prompt_template="{query}",
device="cuda",
max_new_tokens=4096,
)
agent = MyAgent(
chain=chain,
card=AgentCard(
name="coding-agent",
description="A coding assistant agent",
skills=[AgentSkill(id="coding", name="Coding", description="Writes code")],
capabilities=AgentCapabilities(),
default_input_modes=["text"],
default_output_modes=["text"],
url="localhost",
version="0.1.0",
),
)
result = agent.execute(AgentMessage(query="Write a function to compute Fibonacci numbers."))from aap_core.orchestration import SequentialAgent
from aap_transformers.chain import ChatCausalMultiTurnsChain
code_chain = ChatCausalMultiTurnsChain(
model="swiss-ai/Apertus-8B-Instruct-2509",
system_prompt="You are a helpful coding assistant. Write only the function implementation.",
user_prompt_template="{query}",
device="cuda",
max_new_tokens=8192,
)
code_chain.final_response_as_context("code")
doc_chain = ChatCausalMultiTurnsChain(
model="HuggingFaceTB/SmolLM3-3B",
system_prompt="You are a developer advocate. Write docstrings for the provided function.",
user_prompt_template="Input query: {query}\n\nFunction: {context_code}",
device="cuda",
max_new_tokens=8192,
)
sequential_agent = SequentialAgent(
agents=[code_agent, doc_agent],
card=AgentCard(name="pipeline", description="Sequential code-doc pipeline"),
)aap_transformers is a subpackage of the Agent Design Pattern monorepo. It sits on top of aap_core and provides Hugging Face Transformers-specific implementations:
aap_core ← Core agent abstractions (BaseAgent, BaseLLMChain, BaseRetriever, AgentMessage)
└── aap_transformers ← Transformers integrations
├── chain.py ChatCausalMultiTurnsChain
└── retriever.py RetrieverAdapter (planned)
| Package | Description |
|---|---|
aap_core |
Core orchestration framework with agent, chain, and retriever abstractions |
aap_langchain |
LangChain integration (cloud/local chat models) |
aap_llamaindex |
LlamaIndex integration |
aap_dspy |
DSPy integration |
aap_transformers |
Hugging Face Transformers integration (this package) |
- Example notebooks:
example/transformers/
See the project contributing guide for details on development setup, code style, and testing.
This project is licensed under the MIT License — see the LICENSE file for details.