Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@

## ✨ Key features

| Feature | Why it matters |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| **Composable `Agent` model** | Chain or orchestrate agents via `SimpleSequentialAgents`, `AgentManager`, and `AutoAgentManager` for flexible workflows |
| **Auto-routing agent** | `AutoAgentManager` uses a language model to dynamically decide the next agent in the loop |
| **Web-augmented agent** | `InternetAgent` uses `googlesearch`, `requests`, and summarizing agents to fetch and condense live web data |
| **Parallel summarization** | `fast_start` method uses `ThreadPoolExecutor` to speed up web content processing |
| **Prompt-driven summaries** | Summarization is driven by customizable system prompts and token-limited chunking for accurate context |
| **Simple, Pythonic design** | Agents are lightweight Python classes with callable message interfaces—no metaclasses or hidden magic |
| **Memory, BaseMemory** | `BaseMemory` provides foundational memory management for agents, storing conversation history and message objects. It supports adding, retrieving, and clearing memory, offering a flexible design for session-based context, interaction history, or task-specific memory across multiple agent invocations. Ideal for scenarios where the agent needs to recall past interactions for continuity. |
| **SummarizerMemory with summarizer agent** | `SummarizerMemory` extends `BaseMemory` by integrating a summarizing `Agent` that automatically condenses long histories when memory limits are exceeded. This enables agents to maintain compact, relevant context over time, ensuring efficiency without losing key information. |
| Feature | Why it matters |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Composable `Agent` model** | Chain or orchestrate agents via `SimpleSequentialAgents`, `AgentManager`, and `AutoAgentManager` for flexible workflows |
| **Auto-routing agent** | `AutoAgentManager` uses a language model to dynamically decide the next agent in the loop |
| **Web-augmented agent** | `InternetAgent` uses `googlesearch`, `requests`, and summarizing agents to fetch and condense live web data |
| **Parallel summarization** | `fast_start` method uses `ThreadPoolExecutor` to speed up web content processing |
| **Prompt-driven summaries** | Summarization is driven by customizable system prompts and token-limited chunking for accurate context |
| **Simple, Pythonic design** | Agents are lightweight Python classes with callable message interfaces—no metaclasses or hidden magic |
| **Memory, BaseMemory** | `BaseMemory` provides foundational memory management for agents, storing conversation history and message objects. It supports adding, retrieving, and clearing memory, offering a flexible design for session-based context, interaction history, or task-specific memory across multiple agent invocations. Ideal for scenarios where the agent needs to recall past interactions for continuity. |
| **SummarizerMemory with summarizer agent** | `SummarizerMemory` extends `BaseMemory` by integrating a summarizing `Agent` that automatically condenses long histories when memory limits are exceeded. This enables agents to maintain compact, relevant context over time, ensuring efficiency without losing key information. |
| **SmartAgentBuilder for automated agent creation** | `SmartAgentBuilder` automates breaking down a high-level task into structured subtasks, then creates specialized agents for each subtask using a sequential pipeline. It ensures that each agent is precisely configured with a strict role, and outputs an `AutoAgentManager` to run them in coordination. |



Expand Down
16 changes: 12 additions & 4 deletions example/AutoAgent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "6057cd04",
"metadata": {},
"outputs": [
Expand All @@ -29,16 +29,16 @@
"Routing from user -> time_reader \n",
" content: what time is it?\n",
"Routing from time_reader -> date_converter \n",
" content: The current time is 17:03:07.\n"
" content: The current time is 11:28 PM.\n"
]
},
{
"data": {
"text/plain": [
"'زمان فعلی ۱۷:۰۳:۰۷ است. \\n[#finish#]'"
"'زمان کنونی ۱۱:۲۸ شب است. \\n[#finish#]'"
]
},
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -69,6 +69,14 @@
"res = manager.start()\n",
"res.content"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b792a066",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
162 changes: 162 additions & 0 deletions example/SmartAgentBuilder.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "67b890e9",
"metadata": {},
"source": [
"# SmartAgentBuilder\n",
"\n",
"In this example you can see how this module can break tasks and create agents atumatically for you. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "579d2068",
"metadata": {},
"outputs": [],
"source": [
"base_url= \"\" # use your own base_url from api provider or local provider like ollama.\n",
"api_key = \"\" # use your own api_key.\n",
"provider = \"openai\" # openai for openai like provider (vLLM or openrouter) and ollama for local use.\n",
"model = \"gpt-4o-mini\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "10561d55",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Routing from user -> task_generator\n",
"Routing from task_generator -> agent_creator\n",
"Agents are created : broken_word_extractor | correction_suggester | text_compiler\n"
]
}
],
"source": [
"from iragent.agent import AgentFactory\n",
"from iragent.models import SmartAgentBuilder\n",
"\n",
"agent_factory = AgentFactory(\n",
" base_url=base_url,\n",
" api_key=api_key,\n",
" model=model,\n",
" provider=\"openai\"\n",
")\n",
"\n",
"sab = SmartAgentBuilder(\n",
" agent_factory=agent_factory,\n",
")\n",
"task = \"\"\"\n",
"I have a text which contain broken words and i need to correct them. So i want to just pass the broken text,\n",
"then get the corrected text. \n",
"Input: broken text.\n",
"output: corrected text.\n",
"\"\"\"\n",
"\n",
"manager = sab.create_agent(\n",
" task=task,\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1a982ff9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Routing from user -> broken_word_extractor \n",
" content: Ths is a smple txt whre sme of the wrds are mssing lttrs an the sntnce strctre is nt prfct. It may be hrder to undrstand, bt you cn stil knd of figr out wht it mens.\n",
"Routing from broken_word_extractor -> correction_suggester \n",
" content: ['Ths', 'smple', 'txt', 'sme', 'wrds', 'mssing', 'lttrs', 'sntnce', 'strctre', 'nt', 'prfct', 'hrder', 'undrstand', 'bt', 'cn', 'stil', 'knd', 'figr', 'wht', 'mens']\n",
"Routing from correction_suggester -> text_compiler \n",
" content: Here are the suggested corrections for each broken word provided:\n",
"\n",
"1. Ths - This\n",
"2. smple - simple\n",
"3. txt - text\n",
"4. sme - some\n",
"5. wrds - words\n",
"6. mssing - missing\n",
"7. lttrs - letters\n",
"8. sntnce - sentence\n",
"9. strctre - structure\n",
"10. nt - not\n",
"11. prfct - perfect\n",
"12. hrder - harder\n",
"13. und\n",
"Routing from text_compiler -> text_compiler \n",
" content: This simple text has some words missing letters, sentence structure is not perfect, harder to understand.\n",
"Routing from text_compiler -> text_compiler \n",
" content: This simple text has some words missing letters, and the sentence structure is not perfect, making it harder to understand.\n",
"Routing from text_compiler -> text_compiler \n",
" content: This simple text has some words missing letters, and the sentence structure is not perfect, making it harder to understand.\n"
]
}
],
"source": [
"msg = manager.start(message =\"Ths is a smple txt whre sme of the wrds are mssing lttrs an the sntnce strctre is nt prfct. It may be hrder to undrstand, bt you cn stil knd of figr out wht it mens.\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "62c70fda",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'This simple text has some words missing letters, and the sentence structure is not perfect, making it harder to understand.'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msg.content"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c626eacf",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
155 changes: 155 additions & 0 deletions example/SmartPrompt.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "0904114a",
"metadata": {},
"outputs": [],
"source": [
"base_url= \"\" # use your own base_url from api provider or local provider like ollama.\n",
"api_key = \"\" # use your own api_key.\n",
"provider = \"openai\" # openai for openai like provider (vLLM or openrouter) and ollama for local use.\n",
"model = \"gpt-4o-mini\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "686c8d4a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Routing from user -> prompt_maker \n",
" content: \n",
" Here is the input example :\n",
" Yesterday I go shopping and buy some banana and apple and oranges.\n",
" \n",
" Here is the output example i have expected from system.\n",
" apple-banana-orange\n",
"\n",
" \n",
"Routing from prompt_maker -> prompt_reader \n",
" content: Extract the unique fruits mentioned in the input sentence and format them in a hyphen-separated string, sorted alphabetically.\n",
"Routing from prompt_reader -> prompt_maker \n",
" content: Feedback for prompt_maker:\n",
"\n",
"1. **Clarity**: The prompt could benefit from clearer instructions regarding the expected format of the input sentence. For example, specifying whether the fruits will be in a list, a paragraph, or another format would help in understanding how to extract them.\n",
"\n",
"2. **Examples**: Providing an example input sentence along with the expected output would enhance comprehension. This would illustrate the extraction process and the formatting requirements.\n",
"\n",
"3. **Handling Variations**: The prompt does not address potential variations in fruit names (e.g., \"apple\" vs. \"ApPle\") or plural forms (e.g., \"bananas\" vs. \"banana\"). Including instructions on how to handle these variations would improve the robustness of the extraction process.\n",
"\n",
"4. **Error Handling**: There is no mention of how to handle cases where no fruits are found in the input sentence. Clarifying what the output should be in such cases would make the prompt more comprehensive.\n",
"\n",
"5. **Scope**: The prompt assumes that the input will only contain fruits. It might be useful to specify whether to ignore other types of words or if there are any constraints on the types of fruits to be considered.\n",
"\n",
"Overall, refining these aspects would lead to a more effective and user-friendly prompt.\n",
"Routing from prompt_maker -> prompt_reader \n",
" content: You are a text extraction system designed to identify and extract fruit names from a given input sentence. Your task is to process the input and return a list of fruits mentioned, formatted as a comma-separated string. \n",
"\n",
"**Instructions:**\n",
"1. Identify and extract all fruit names from the input sentence. \n",
"2. The output should be in lowercase and include only the names of the fruits, separated by commas.\n",
"3. Handle variations in fruit names (e.g., \"apple\" vs. \"ApPle\") and plural forms (e.g., \"bananas\" vs. \"banana\") by standardizing them to their singular, lowercase form.\n",
"4. If no fruits are found in the input sentence, return an empty string.\n",
"5. Ignore any other types of words or items that are not fruits.\n",
"\n",
"**Example:**\n",
"Input: \"I went to the market and bought some bananas and apples.\"\n",
"Output: \"banana, apple\"\n",
"\n",
"Now, process the following input: \n",
"{input_data}\n",
"Routing from prompt_reader -> prompt_maker \n",
" content: Feedback for the prompt maker:\n",
"\n",
"1. **Clarity and Specificity**: The prompt is generally clear, but it could benefit from more specific examples of fruit names to ensure that the system can recognize a wider variety of fruits. Including a list of common fruits or examples of less common fruits could help improve the extraction accuracy.\n",
"\n",
"2. **Handling Ambiguities**: The prompt does not address how to handle ambiguous terms that may refer to fruits in some contexts but not in others (e.g., \"peach\" in \"peach tree\"). Providing guidance on how to deal with such cases would enhance the robustness of the extraction system.\n",
"\n",
"3. **Input Format**: The placeholder `{input_data}` is not defined in the prompt. It would be helpful to specify the expected format of the input data (e.g., a complete sentence, a list of sentences) to avoid confusion.\n",
"\n",
"4. **Output Format**: While the output format is specified as a comma-separated string, it might be useful to clarify whether there should be a space after each comma or if the fruits should be listed without any spaces.\n",
"\n",
"5. **Error Handling**: The prompt mentions returning an empty string if no fruits are found, but it does not specify how to handle potential errors in input (e.g., if the input is not a valid sentence). Including error handling instructions could improve the system's reliability.\n",
"\n",
"Overall, while the prompt provides a solid foundation for a text extraction system, addressing these areas could enhance its effectiveness and clarity.\n"
]
}
],
"source": [
"from iragent.agent import AgentFactory\n",
"from iragent.models import SmartPrompt\n",
"\n",
"agent_factory = AgentFactory(\n",
" base_url=base_url,\n",
" api_key=api_key,\n",
" model=model,\n",
" provider=\"openai\"\n",
")\n",
"\n",
"sp = SmartPrompt(agent_factory=agent_factory)\n",
"i = \"Yesterday I go shopping and buy some banana and apple and oranges.\"\n",
"o = \"apple-banana-orange\"\n",
"msg = sp.generate(\n",
" input=i,\n",
" output=o\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1026a3b8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Extract all fruit names from the provided input sentence. The input will be a complete sentence containing various items, including fruits. Return the extracted fruit names as a comma-separated string without spaces after the commas. If no fruits are found, return an empty string. Handle ambiguous terms carefully, ensuring that only recognized fruit names are included. The input format will be a single sentence, and ensure to validate that the input is a proper sentence before processing. \\n\\nExample input: \"I went to the market and bought oranges, peaches, and grapes.\"\\nExpected output: \"oranges,peaches,grapes\"'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msg.content"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00083c29",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file modified iragent/__pycache__/agent.cpython-312.pyc
Binary file not shown.
Binary file modified iragent/__pycache__/memory.cpython-312.pyc
Binary file not shown.
Binary file modified iragent/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified iragent/__pycache__/prompts.cpython-312.pyc
Binary file not shown.
Binary file modified iragent/__pycache__/tools.cpython-312.pyc
Binary file not shown.
Binary file modified iragent/__pycache__/utility.cpython-312.pyc
Binary file not shown.
Loading