Skip to content

About

Agent design pattern transformers integration package

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

aap_transformers

Hugging Face Transformers integration for the Agent Design Pattern framework.

PyPI - License PyPI - Downloads PyPI - Version Python Version

What is this?

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.

Quick Start

pip install aap_transformers
from 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,
)

Features

  • ChatCausalMultiTurnsChain: A Transformers-backed multi-turn chain that extends BaseCausalMultiTurnsChain from aap_core. Supports system prompts, user templates, device placement (CPU/CUDA), and configurable generation parameters.
  • Local model inference: Run open-weight models directly via the transformers library — 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's TokenUsage type for consistent tracking across agents.

Installation

Core dependency

aap_transformers depends on aap_core. Install both together:

pip install aap_core aap_transformers

Optional dependencies

# Weaviate integration
pip install "aap_transformers[weaviate]"

Development setup

uv sync --group dev

Usage

Building an agent with a Transformers model

from 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."))

Multi-agent sequential pipeline

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"),
)

Architecture

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)

Documentation

Contributing

See the project contributing guide for details on development setup, code style, and testing.

License

This project is licensed under the MIT License — see the LICENSE file for details.

About

Agent design pattern transformers integration package

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages