Agent
Custom LLM agents with decorators, tools, and advanced orchestration.
Overview
The Agent
class is a task-oriented agent system that executes language model-based tasks in a customizable way. It works with LangChain compatible LLMs and has a customizable structure to plan your tasks and interact with tools when needed.
The main objective of this system:
- Ensuring modularity
- Designing each
Agent
to be task-oriented - Ability to change behavior with custom start (
custom_start
) functions when needed
Agent
is a modular, task-focused abstraction for building intelligent LLM-powered units. It supports decorators, dynamic prompts, custom execution logic, and integration with tools โ enabling developers to compose flexible and reusable agent-based systems.
๐ค Overview
Each Agent
acts like a focused, autonomous LLM task handler.
Key principles:
- Encapsulation of specific responsibilities
- Decorator support for logic customization
- Full control over prompt engineering and execution
- Seamless tool usage
- Compatible with LangChain LLMs and Tool protocols
๐ง Basic Example
โ๏ธ Parameters
Parameter | Type | Description |
---|---|---|
name | str | Unique identifier for the agent |
llm | BaseChatModel | LangChain-compatible LLM instance |
tools (opt) | list[Tool] | Optional tools the agent can use |
system_prompt (opt) | str | Initial system instruction |
custom_start (opt) | Callable | Override logic using a custom function |
โจ Functional Prompt via Decorator
You can define the system prompt dynamically using decorators:
๐ Custom Execution with custom_start
Decorators can fully override agent behavior. The custom_start
method receives the following arguments:
input
tools
llm
system_prompt
๐ Using Tools with Agents
Each Tool
includes a name, description, and a callable. Tools are directly usable in the agent flow.
๐ฆ AgentProtocol Support
You can also implement lightweight custom agents using the AgentProtocol interface:
๐ฌ Advanced Multi-Agent Flow
โถ๏ธ Execution: start(input, verbose=False, **kwargs)
Main method to invoke agent logic. Falls back to built-in logic if no custom_start
is provided.
๐ค Output Format
๐ง Best Practices
- Keep each agent task-specific (Single Responsibility Principle)
- Use decorators for testable custom behavior
- Use clear and minimal
system_prompt
values - Prefer stateless
custom_start
logic - Tools are powerful when used with dynamic input templates
๐งฉ Interface: AgentProtocol (TS)
๐งต Orchestration with TaskFlow
Combine agents into a pipeline with TaskFlow
:
๐ See Also
Tool
for defining custom toolsTaskFlow
for full orchestration capabilities
chainless.Agent
helps you build modular AI logic, encapsulating capabilities into reusable and composable intelligent agents.