agentsflowcompiler-lib 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. agentsflowcompiler-lib-0.1.6/LICENSE +21 -0
  2. agentsflowcompiler-lib-0.1.6/PKG-INFO +623 -0
  3. agentsflowcompiler-lib-0.1.6/README.md +564 -0
  4. agentsflowcompiler-lib-0.1.6/pyproject.toml +89 -0
  5. agentsflowcompiler-lib-0.1.6/setup.cfg +4 -0
  6. agentsflowcompiler-lib-0.1.6/src/agentsflow/__init__.py +53 -0
  7. agentsflowcompiler-lib-0.1.6/src/agentsflow/_prod.py +72 -0
  8. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/__init__.py +9 -0
  9. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/_utils.py +122 -0
  10. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/agent.py +237 -0
  11. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/llm_loop.py +137 -0
  12. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/log_dispatcher.py +97 -0
  13. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/prompt_builder.py +48 -0
  14. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/run_context.py +39 -0
  15. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/stats.py +240 -0
  16. agentsflowcompiler-lib-0.1.6/src/agentsflow/agent/tools.py +126 -0
  17. agentsflowcompiler-lib-0.1.6/src/agentsflow/builder/__init__.py +11 -0
  18. agentsflowcompiler-lib-0.1.6/src/agentsflow/builder/agents_builder.py +110 -0
  19. agentsflowcompiler-lib-0.1.6/src/agentsflow/config.py +46 -0
  20. agentsflowcompiler-lib-0.1.6/src/agentsflow/constants.py +49 -0
  21. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/__init__.py +112 -0
  22. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/agent_api.py +414 -0
  23. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/__init__.py +4 -0
  24. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/agent_helper.py +234 -0
  25. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/duplicate_helper.py +82 -0
  26. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/monitoring_helper.py +12 -0
  27. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/processing_helper.py +66 -0
  28. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/prod_sync_helper.py +173 -0
  29. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/project_helper.py +119 -0
  30. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/helper/tool_helper.py +231 -0
  31. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/model_api.py +74 -0
  32. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/monitoring_api.py +297 -0
  33. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/monitoring_types.py +72 -0
  34. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/processing_api.py +275 -0
  35. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/project_api.py +123 -0
  36. agentsflowcompiler-lib-0.1.6/src/agentsflow/dev/tool_api.py +686 -0
  37. agentsflowcompiler-lib-0.1.6/src/agentsflow/errors.py +72 -0
  38. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/__init__.py +13 -0
  39. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/_error_utils.py +27 -0
  40. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/ai21_client.py +38 -0
  41. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/amazon_client.py +204 -0
  42. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/anthropic_client.py +179 -0
  43. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/base.py +70 -0
  44. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/cohere_client.py +118 -0
  45. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/factory.py +105 -0
  46. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/google_client.py +164 -0
  47. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/mistral_client.py +38 -0
  48. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/openai_client.py +35 -0
  49. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/openai_compatible_client.py +204 -0
  50. agentsflowcompiler-lib-0.1.6/src/agentsflow/llm/provider_registry.py +228 -0
  51. agentsflowcompiler-lib-0.1.6/src/agentsflow/logging_utils.py +58 -0
  52. agentsflowcompiler-lib-0.1.6/src/agentsflow/py.typed +0 -0
  53. agentsflowcompiler-lib-0.1.6/src/agentsflow/schema/__init__.py +19 -0
  54. agentsflowcompiler-lib-0.1.6/src/agentsflow/schema/agent_config_schema.py +258 -0
  55. agentsflowcompiler-lib-0.1.6/src/agentsflow/schema/manifest_schema.py +11 -0
  56. agentsflowcompiler-lib-0.1.6/src/agentsflow/schema/project_config_schema.py +87 -0
  57. agentsflowcompiler-lib-0.1.6/src/agentsflow/schema/tool_config_schema.py +116 -0
  58. agentsflowcompiler-lib-0.1.6/src/agentsflow/schema/tool_schema.py +25 -0
  59. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/__init__.py +12 -0
  60. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/base32_base58/tool.py +105 -0
  61. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/base32_base58/tool.yaml +24 -0
  62. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/base64_codec/tool.py +44 -0
  63. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/base64_codec/tool.yaml +24 -0
  64. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/calculator/tool.py +41 -0
  65. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/calculator/tool.yaml +24 -0
  66. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/csv_parser/tool.py +69 -0
  67. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/csv_parser/tool.yaml +28 -0
  68. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/date_formatter/tool.py +37 -0
  69. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/date_formatter/tool.yaml +24 -0
  70. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/diff_checker/tool.py +46 -0
  71. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/diff_checker/tool.yaml +24 -0
  72. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/directory_tree/tool.py +95 -0
  73. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/directory_tree/tool.yaml +28 -0
  74. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/env_reader/tool.py +46 -0
  75. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/env_reader/tool.yaml +24 -0
  76. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/file_size_reader/tool.py +59 -0
  77. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/file_size_reader/tool.yaml +16 -0
  78. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/hash_generator/tool.py +40 -0
  79. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/hash_generator/tool.yaml +20 -0
  80. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/http_headers_analyzer/tool.py +69 -0
  81. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/http_headers_analyzer/tool.yaml +16 -0
  82. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/ip_lookup/tool.py +52 -0
  83. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/ip_lookup/tool.yaml +16 -0
  84. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/json_validator/tool.py +41 -0
  85. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/json_validator/tool.yaml +20 -0
  86. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/jwt_decoder/tool.py +64 -0
  87. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/jwt_decoder/tool.yaml +16 -0
  88. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/markdown_converter/tool.py +121 -0
  89. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/markdown_converter/tool.yaml +20 -0
  90. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/password_strength/tool.py +114 -0
  91. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/password_strength/tool.yaml +16 -0
  92. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/path_normalizer/tool.py +41 -0
  93. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/path_normalizer/tool.yaml +20 -0
  94. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/ping_checker/tool.py +128 -0
  95. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/ping_checker/tool.yaml +24 -0
  96. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/port_scanner/tool.py +98 -0
  97. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/port_scanner/tool.yaml +24 -0
  98. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/random_generator/tool.py +80 -0
  99. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/random_generator/tool.yaml +36 -0
  100. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/regex_tester/tool.py +65 -0
  101. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/regex_tester/tool.yaml +24 -0
  102. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/slug_generator/tool.py +47 -0
  103. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/slug_generator/tool.yaml +24 -0
  104. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/temp_file_generator/tool.py +36 -0
  105. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/temp_file_generator/tool.yaml +24 -0
  106. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/text_summarizer/tool.py +83 -0
  107. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/text_summarizer/tool.yaml +20 -0
  108. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/timestamp_converter/tool.py +82 -0
  109. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/timestamp_converter/tool.yaml +24 -0
  110. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/title_case_converter/tool.py +80 -0
  111. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/title_case_converter/tool.yaml +20 -0
  112. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/url_parser/tool.py +56 -0
  113. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/url_parser/tool.yaml +16 -0
  114. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/uuid_generator/tool.py +32 -0
  115. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/uuid_generator/tool.yaml +20 -0
  116. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/word_counter/tool.py +33 -0
  117. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/builtins/word_counter/tool.yaml +16 -0
  118. agentsflowcompiler-lib-0.1.6/src/agentsflow/tools/registry.py +96 -0
  119. agentsflowcompiler-lib-0.1.6/src/agentsflow/types.py +83 -0
  120. agentsflowcompiler-lib-0.1.6/src/agentsflow/utils/__init__.py +25 -0
  121. agentsflowcompiler-lib-0.1.6/src/agentsflow/utils/audit.py +78 -0
  122. agentsflowcompiler-lib-0.1.6/src/agentsflow/utils/config_io.py +51 -0
  123. agentsflowcompiler-lib-0.1.6/src/agentsflow/utils/fs.py +85 -0
  124. agentsflowcompiler-lib-0.1.6/src/agentsflow/utils/manifest_io.py +111 -0
  125. agentsflowcompiler-lib-0.1.6/src/agentsflow/utils/paths.py +70 -0
  126. agentsflowcompiler-lib-0.1.6/src/agentsflow/validate/__init__.py +37 -0
  127. agentsflowcompiler-lib-0.1.6/src/agentsflow/validate/agent.py +139 -0
  128. agentsflowcompiler-lib-0.1.6/src/agentsflow/validate/processing.py +60 -0
  129. agentsflowcompiler-lib-0.1.6/src/agentsflowcompiler_lib.egg-info/PKG-INFO +623 -0
  130. agentsflowcompiler-lib-0.1.6/src/agentsflowcompiler_lib.egg-info/SOURCES.txt +132 -0
  131. agentsflowcompiler-lib-0.1.6/src/agentsflowcompiler_lib.egg-info/dependency_links.txt +1 -0
  132. agentsflowcompiler-lib-0.1.6/src/agentsflowcompiler_lib.egg-info/requires.txt +61 -0
  133. agentsflowcompiler-lib-0.1.6/src/agentsflowcompiler_lib.egg-info/top_level.txt +1 -0
  134. agentsflowcompiler-lib-0.1.6/tests/test_genai_timeout.py +15 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Shahar Fadlon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,623 @@
1
+ Metadata-Version: 2.1
2
+ Name: agentsflowcompiler-lib
3
+ Version: 0.1.6
4
+ Summary: Modular AI agent framework — build, configure, and run LLM agents
5
+ Author: Shahar Fadlon
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Shahar Fadlon
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/shaharfadlon/AgentFlow
29
+ Project-URL: Repository, https://github.com/shaharfadlon/AgentFlow
30
+ Project-URL: Bug Tracker, https://github.com/shaharfadlon/AgentFlow/issues
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
34
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Typing :: Typed
41
+ Requires-Python: >=3.10
42
+ Description-Content-Type: text/markdown
43
+ Provides-Extra: dev
44
+ Provides-Extra: openai
45
+ Provides-Extra: anthropic
46
+ Provides-Extra: google
47
+ Provides-Extra: azure
48
+ Provides-Extra: amazon
49
+ Provides-Extra: xai
50
+ Provides-Extra: mistral
51
+ Provides-Extra: cohere
52
+ Provides-Extra: deepseek
53
+ Provides-Extra: ai21
54
+ Provides-Extra: perplexity
55
+ Provides-Extra: meta
56
+ Provides-Extra: ollama
57
+ Provides-Extra: all
58
+ License-File: LICENSE
59
+
60
+ # AgentsFlowCompiler
61
+
62
+ A modular Python framework for building, configuring, and running LLM-powered AI agents. Define agents in YAML, equip them with tools, and run them with a single function call.
63
+
64
+ ---
65
+
66
+ ## Installation
67
+
68
+ ```bash
69
+ # Core (production runtime only)
70
+ pip install AgentsFlowCompiler-lib
71
+
72
+ # With dev tools (agent management, monitoring, CRUD API)
73
+ pip install AgentsFlowCompiler-lib[dev]
74
+
75
+ # With specific LLM providers
76
+ pip install AgentsFlowCompiler-lib[openai]
77
+ pip install AgentsFlowCompiler-lib[anthropic]
78
+ pip install AgentsFlowCompiler-lib[google]
79
+ pip install AgentsFlowCompiler-lib[ollama]
80
+
81
+ # Everything
82
+ pip install AgentsFlowCompiler-lib[all]
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Quick Start
88
+
89
+ ### Production — Load & Run
90
+
91
+ ```python
92
+ from agentsflow import load_agents, AgentsFlowConfig
93
+
94
+ # Load all agents from a directory
95
+ agents = load_agents("/path/to/my_project")
96
+
97
+ # Run an agent
98
+ result = agents["analyzer"].run("What is the GDP of France?")
99
+ print(result.output) # The answer
100
+ print(result.token_input, result.token_output) # Token metadata
101
+
102
+ # Agent metadata properties
103
+ print(agent.name) # "analyzer"
104
+ print(agent.model) # "gpt-4o"
105
+ print(agent.provider) # "openai"
106
+
107
+ # With a .env file for API keys
108
+ agents = load_agents("/path/to/my_project", env_path="/path/to/.env")
109
+
110
+ # With SDK config (log level, network silencing, structured logging)
111
+ config = AgentsFlowConfig(log_level="INFO", silence_network_loggers=True, log_format="json")
112
+ agents = load_agents("/path/to/my_project", config=config)
113
+ ```
114
+
115
+ ### Development — Create & Manage
116
+
117
+ ```python
118
+ from agentsflow.dev import create_project, create_agent, add_tool
119
+ from agentsflow.schema.agent_config_schema import AgentModelConfig, Prompt
120
+ from agentsflow.schema.tool_config_schema import ToolIdentityConfig, ToolConfig
121
+
122
+ # Create a project
123
+ create_project("My AI Project", dev_path="/path/to/dev", prod_path="/path/to/prod")
124
+
125
+ # Create an agent
126
+ create_agent(
127
+ base_dir="/path/to/dev",
128
+ agent_name="researcher",
129
+ model_config=AgentModelConfig(model="gpt-4o", temperature=0.3),
130
+ description="Research assistant that finds and summarizes information",
131
+ prompts=Prompt(
132
+ instruction="You are a research assistant. Be thorough and cite sources.",
133
+ think="Break complex questions into sub-questions before answering.",
134
+ ),
135
+ )
136
+
137
+ # Add a tool (script stored at tools/custom_tools/web_search/tool.py)
138
+ add_tool(
139
+ base_dir="/path/to/dev",
140
+ script="def search(query: str, max_results: int = 5):\n return []",
141
+ identity=ToolIdentityConfig(
142
+ name="web_search",
143
+ description="Search the web for current information",
144
+ category="search",
145
+ ),
146
+ config=ToolConfig(
147
+ function_name="search",
148
+ parameters={
149
+ "query": {"type": "string", "description": "Search query", "required": True},
150
+ "max_results": {"type": "number", "description": "Max results", "required": False, "default": 5},
151
+ },
152
+ returns={"type": "array", "description": "Search results"},
153
+ ),
154
+ agent_name="researcher",
155
+ )
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Core Concepts
161
+
162
+ ### What is an Agent?
163
+
164
+ An agent is an LLM-powered unit that:
165
+
166
+ 1. **Receives** a user prompt
167
+ 2. **Optionally preprocesses** the input (custom Python function)
168
+ 3. **Sends** a system prompt + user message to an LLM
169
+ 4. **Can use tools** — the LLM decides when to call them, executes them, and feeds results back
170
+ 5. **Optionally postprocesses** the output (custom Python function)
171
+ 6. **Returns** a `RunResult` object containing the output and metadata
172
+
173
+ ```
174
+ User Input → [Preprocess] → LLM ⇄ Tools → [Postprocess] → Final Output
175
+ ```
176
+
177
+ ### Project Structure
178
+
179
+ A typical project looks like this:
180
+
181
+ ```
182
+ my_project/
183
+ ├── MyProject.afproj # Optional project metadata & env config
184
+ ├── config/
185
+ │ └── agents.yaml # Agent manifest (lists all agents)
186
+ ├── agents/
187
+ │ ├── researcher/
188
+ │ │ ├── config.yaml # Agent configuration
189
+ │ │ ├── instruction.md # System instruction prompt
190
+ │ │ ├── think.md # Thinking guidelines (optional)
191
+ │ │ ├── return.md # Output format instructions (optional)
192
+ │ │ ├── example.md # Few-shot examples (optional)
193
+ │ │ ├── custom_tools.py # Custom tool functions (optional)
194
+ │ │ └── logs/
195
+ │ │ ├── run_history/ # Run logs
196
+ │ │ ├── audit_logs/ # Audit trail
197
+ │ │ ├── prompt_history/ # Prompt history
198
+ │ │ └── token_usage/ # Token usage logs
199
+ │ └── writer/
200
+ │ ├── config.yaml
201
+ │ ├── instruction.md
202
+ │ └── logs/
203
+ └── tools/ # Shared built-in tools
204
+ ├── calculator/
205
+ │ ├── tool.yaml
206
+ │ └── tool.py
207
+ └── web_search/
208
+ ├── tool.yaml
209
+ └── tool.py
210
+ ```
211
+
212
+ ### Agent Configuration (YAML)
213
+
214
+ Each agent is defined by a `config.yaml` file:
215
+
216
+ ```yaml
217
+ researcher:
218
+ # Identity
219
+ agent_id: "node_001"
220
+ description: "Research assistant"
221
+
222
+ # Model
223
+ model: gpt-4o # or claude-sonnet-4-20250514, gemini-pro, llama3, etc.
224
+ provider: openai # auto-detected if not set
225
+ temperature: 0.3
226
+ max_tokens: 4096
227
+
228
+ # Prompts (relative paths to .md files)
229
+ instruction_path: instruction.md
230
+ think_path: think.md # optional: thinking guidelines
231
+ return_path: return.md # optional: output format rules
232
+ example_path: example.md # optional: few-shot examples
233
+
234
+ # Pre/Post Processing (optional)
235
+ preprocess_path: preprocess.py
236
+ preprocess_function_name: preprocess
237
+ postprocess_path: postprocess.py
238
+ postprocess_function_name: postprocess
239
+
240
+ # Output Format
241
+ return_format: text # text | json | json_object | markdown
242
+ json_schema_path: schema.json # optional: for structured JSON output
243
+
244
+ # Tools
245
+ tools:
246
+ - name: calculator
247
+ custom: false
248
+ - name: company_lookup
249
+ custom: true
250
+ description: "Look up company info"
251
+ path: custom_tools.py
252
+ function_name: lookup
253
+ parameters:
254
+ query:
255
+ type: string
256
+ description: "Company name or ticker"
257
+ required: true
258
+ ```
259
+
260
+ ---
261
+
262
+ ## System Prompt Assembly
263
+
264
+ The agent's system prompt is assembled from multiple files in this order:
265
+
266
+ ```
267
+ ┌─────────────────┐
268
+ │ instruction.md │ ← Main system instruction (required)
269
+ ├─────────────────┤
270
+ │ think.md │ ← How the agent should reason (optional)
271
+ ├─────────────────┤
272
+ │ return.md │ ← Output format guidelines (optional)
273
+ ├─────────────────┤
274
+ │ example.md │ ← Few-shot examples (optional)
275
+ └─────────────────┘
276
+
277
+ Combined System Prompt → sent to LLM
278
+ ```
279
+
280
+ This modular approach lets you reuse and swap prompt sections independently.
281
+
282
+ ---
283
+
284
+ ## Tools
285
+
286
+ Tools give agents the ability to perform actions — search the web, calculate math, call APIs, read files, and anything else you can write in Python.
287
+
288
+ ### Built-in Tools
289
+
290
+ Built-in tools are shared across all agents. Each is a folder inside `tools/`:
291
+
292
+ | Tool | Category | Description |
293
+ |------|----------|-------------|
294
+ | `calculator` | math | Evaluate math expressions safely (sqrt, log, sin, +, -, etc.) |
295
+ | `web_search` | search | Search the web for current information |
296
+
297
+ #### Using a built-in tool:
298
+
299
+ ```yaml
300
+ tools:
301
+ - name: calculator
302
+ custom: false
303
+ ```
304
+
305
+ ### Custom Tools
306
+
307
+ Custom tools are Python functions specific to an agent.
308
+
309
+ **Step 1:** Write the function:
310
+
311
+ ```python
312
+ # agents/researcher/custom_tools.py
313
+ def lookup_company(query: str) -> dict:
314
+ """Look up company information."""
315
+ # your logic here
316
+ return {"name": "Apple", "sector": "Technology", "market_cap": "3.4T"}
317
+ ```
318
+
319
+ **Step 2:** Define in YAML:
320
+
321
+ ```yaml
322
+ tools:
323
+ - name: company_lookup
324
+ custom: true
325
+ description: "Look up company information by name or ticker"
326
+ category: finance
327
+ path: custom_tools.py
328
+ function_name: lookup_company
329
+ parameters:
330
+ query:
331
+ type: string
332
+ description: "Company name or stock ticker"
333
+ required: true
334
+ returns:
335
+ type: object
336
+ description: "Company info with name, sector, market_cap"
337
+ ```
338
+
339
+ ### Tool Parameter Fields
340
+
341
+ | Field | Type | Required | Description |
342
+ |-------|------|----------|-------------|
343
+ | `type` | string | ✅ | `string`, `number`, `boolean`, `array`, `object` |
344
+ | `description` | string | ✅ | What this parameter does (the LLM reads this) |
345
+ | `required` | boolean | ❌ | Default: `false` |
346
+ | `default` | any | ❌ | Default value if not provided |
347
+ | `enum` | array | ❌ | List of allowed values |
348
+
349
+ ### How Tool Calling Works at Runtime
350
+
351
+ ```
352
+ 1. Agent loads → ToolRegistry reads YAML, imports Python functions
353
+ 2. Agent.run() called → LLM receives tool schemas in API request
354
+ 3. LLM wants a tool → Returns tool_calls: [{name, arguments}]
355
+ 4. Agent executes → ToolRegistry.execute(name, args) → runs Python function
356
+ 5. Result sent back → Added to messages as role: "tool"
357
+ 6. LLM sees result → Calls another tool or returns final answer
358
+ 7. Loop limit → Max 10 rounds (prevents infinite loops)
359
+ ```
360
+
361
+ ---
362
+
363
+ ## Pre/Post Processing
364
+
365
+ ### Preprocess
366
+
367
+ A Python function that transforms user input **before** it reaches the LLM:
368
+
369
+ ```python
370
+ # preprocess.py
371
+ def preprocess(user_input: str) -> str:
372
+ """Add context, clean input, augment with RAG results, etc."""
373
+ context = fetch_relevant_docs(user_input)
374
+ return f"Context:\n{context}\n\nQuestion: {user_input}"
375
+ ```
376
+
377
+ ### Postprocess
378
+
379
+ A Python function that transforms LLM output **after** the response:
380
+
381
+ ```python
382
+ # postprocess.py
383
+ def postprocess(llm_output):
384
+ """Parse, validate, save to DB, trigger notifications, etc."""
385
+ data = json.loads(llm_output)
386
+ save_to_database(data)
387
+ return data
388
+ ```
389
+
390
+ ---
391
+
392
+ ## LLM Providers
393
+
394
+ The framework auto-detects the provider based on model name. You can also set it explicitly via `provider` in the config.
395
+
396
+ | Provider | Models | API Key Env Var |
397
+ |----------|--------|-----------------|
398
+ | **OpenAI** | gpt-4, gpt-4o, gpt-4o-mini, o1, o3 | `OPENAI_API_KEY` |
399
+ | **Anthropic** | claude-sonnet-4-20250514, claude-3-haiku, claude-3-opus | `ANTHROPIC_API_KEY` |
400
+ | **Google** | gemini-pro, gemini-1.5-flash, gemini-2.0 | `GOOGLE_API_KEY` |
401
+ | **Ollama** | llama3, mistral, phi, qwen, deepseek, codellama | No key needed (local) |
402
+
403
+ ---
404
+
405
+ ## API Reference
406
+
407
+ See [helper/API_REFERENCE.md](helper/API_REFERENCE.md) for the complete reference. Summary:
408
+
409
+ ### PROD API
410
+
411
+ ```python
412
+ from agentsflow import load_agents, AgentsFlowConfig
413
+ ```
414
+
415
+ | Function | Description |
416
+ |----------|-------------|
417
+ | `load_agents(agents_dir, env_path=None, config=None)` | Load all agents → `dict[str, Agent]`. `config`: optional `AgentsFlowConfig` |
418
+ | `AgentsFlowConfig` | SDK-wide config: `log_level`, `silence_network_loggers`, `log_format` |
419
+
420
+ ### DEV API
421
+
422
+ Available with `pip install AgentsFlowCompiler-lib[dev]`. Project metadata lives in an optional `.afproj` file; agent/tool/processing/monitoring APIs operate directly on the DEV `base_dir`.
423
+
424
+ #### Project
425
+
426
+ | Function | Description |
427
+ |----------|-------------|
428
+ | `create_project(project_name, dev_path, prod_path, ...)` | Create optional `.afproj` metadata file |
429
+ | `edit_project(project_config_path, **updates)` | Edit project fields |
430
+ | `get_project(project_config_path)` | Read project config |
431
+
432
+ #### Agent
433
+
434
+ | Function | Description |
435
+ |----------|-------------|
436
+ | `create_agent(base_dir, agent_name, model_config, ...)` | Create agent directory + config + prompts |
437
+ | `edit_agent(base_dir, agent_id/name, ...)` | Edit config fields (pass only what changes) |
438
+ | `delete_agent(base_dir, agent_id/name)` | Delete agent + remove from manifest |
439
+ | `duplicate_agent(base_dir, new_name, source_name/id)` | Deep copy with new name |
440
+ | `validate_agent(base_dir, agent_id/name)` | Raise `AgentsFlowConfigError` on invalid config |
441
+ | `get_agent_config(base_dir, agent_id/name)` | Get full `AgentConfig` |
442
+ | `get_all_agents(base_dir)` | List all registered agents |
443
+
444
+ #### Tools
445
+
446
+ | Function | Description |
447
+ |----------|-------------|
448
+ | `add_tool(base_dir, script, identity, config, agent_name/id)` | Add custom tool (`ToolIdentityConfig` + `ToolConfig`) |
449
+ | `edit_tool(base_dir, tool_name/id, agent_name/id, ...)` | Edit tool fields |
450
+ | `remove_tool(base_dir, tool_name/id, agent_name/id)` | Remove tool from agent |
451
+ | `get_custom_tools(base_dir, agent_name/id)` | List custom tools on agent |
452
+ | `get_agent_builtin_tools(base_dir, agent_name/id)` | List built-in tools used by agent |
453
+ | `get_all_builtin_tools(tools_dir)` | List all available built-in tools |
454
+ | `get_full_script_tool(base_dir, agent_name/id, tool_name/id)` | Read tool Python script from disk |
455
+
456
+ #### Processing
457
+
458
+ | Function | Description |
459
+ |----------|-------------|
460
+ | `add_preprocess(base_dir, agent_name/id)` | Add preprocess (creates default script) |
461
+ | `edit_preprocess(base_dir, agent_name/id, script)` | Replace preprocess script |
462
+ | `remove_preprocess(base_dir, agent_name/id)` | Remove preprocess |
463
+ | `add_postprocess(base_dir, agent_name/id)` | Add postprocess (creates default script) |
464
+ | `edit_postprocess(base_dir, agent_name/id, script)` | Replace postprocess script |
465
+ | `remove_postprocess(base_dir, agent_name/id)` | Remove postprocess |
466
+ | `get_preprocess_script(base_dir, agent_name/id)` | Read preprocess script from disk |
467
+ | `get_postprocess_script(base_dir, agent_name/id)` | Read postprocess script from disk |
468
+
469
+ #### Monitoring
470
+
471
+ | Function | Description |
472
+ |----------|-------------|
473
+ | `get_prompt_history(base_dir, agent_name)` | History of system prompt changes |
474
+ | `get_prompt_from_hash(base_dir, hash, agent_name/id)` | Read stored prompt by hash |
475
+ | `get_run_history(base_dir, agent_name, from_date, to_date)` | I/O logs with date filtering |
476
+ | `get_run_details(base_dir, rid, agent_name/id)` | Single run by run ID |
477
+ | `get_token_usage(base_dir, agent_name, from_date, to_date)` | Token stats aggregate |
478
+ | `get_audit_logs(base_dir, agent_name/id)` | Audit log entries |
479
+ | `get_audit_log_from_timestamp(base_dir, timestamp, agent_name/id)` | Single audit entry by timestamp |
480
+
481
+ ---
482
+
483
+ ## Architecture
484
+
485
+ ```
486
+ AgentsFlowCompiler-lib
487
+ ├── agentsflow/ Python package (import name)
488
+ │ ├── __init__.py PROD entry: load_agents()
489
+ │ ├── _prod.py Production loader + .env support
490
+ │ │
491
+ │ ├── agent/ Core agent runtime
492
+ │ │ ├── agent.py Agent class (run loop)
493
+ │ │ ├── config.py Path resolution
494
+ │ │ ├── prompts.py Prompt assembly & pre/post process
495
+ │ │ ├── tools.py Tool execution wrapper
496
+ │ │ ├── stats.py Logging & token tracking
497
+ │ │ └── _utils.py Shared helpers
498
+ │ │
499
+ │ ├── llm/ LLM provider abstraction
500
+ │ │ ├── base.py LLMClient abstract interface
501
+ │ │ ├── openai_client.py OpenAI implementation
502
+ │ │ ├── anthropic_client.py Anthropic implementation
503
+ │ │ ├── google_client.py Google Gemini implementation
504
+ │ │ ├── ollama_client.py Ollama (local) implementation
505
+ │ │ └── factory.py Auto-detect & create client
506
+ │ │
507
+ │ ├── schema/ Pydantic data models
508
+ │ │ ├── agent_config_schema.py AgentConfig
509
+ │ │ ├── tool_config_schema.py ToolConfig
510
+ │ │ └── tool_schema.py ToolParameterConfig
511
+ │ │
512
+ │ ├── tools/ Tool registry
513
+ │ │ └── registry.py Load, register, execute tools
514
+ │ │
515
+ │ ├── builder/ Agent construction
516
+ │ │ └── agents_builder.py YAML manifest → Agent instances
517
+ │ │
518
+ │ └── dev/ DEV API (25 functions)
519
+ │ ├── project_api.py
520
+ │ ├── agent_api.py
521
+ │ ├── tool_api.py
522
+ │ ├── processing_api.py
523
+ │ └── monitoring_api.py
524
+
525
+ └── tests/ 101 tests
526
+ ├── micro/ Unit tests (99)
527
+ │ ├── agent/
528
+ │ └── api/
529
+ └── macro/ Integration tests (2)
530
+ ```
531
+
532
+ ### Design Principles (SOLID)
533
+
534
+ | Principle | How It's Applied |
535
+ |-----------|-----------------|
536
+ | **Single Responsibility** | Each file does one thing (one LLM provider per file, one schema per file) |
537
+ | **Open/Closed** | Add a new LLM provider = new file + 2 lines in `factory.py`, no existing code changes |
538
+ | **Liskov Substitution** | All providers implement `LLMClient` ABC and are fully interchangeable |
539
+ | **Interface Segregation** | `LLMClient` has a minimal interface: `chat()` + `provider_name` |
540
+ | **Dependency Inversion** | `Agent` depends on the `LLMClient` abstraction, never on concrete providers |
541
+
542
+ ---
543
+
544
+ ## Testing
545
+
546
+ ```bash
547
+ # All tests (101)
548
+ pytest tests/
549
+
550
+ # Unit tests only
551
+ pytest tests/micro/
552
+
553
+ # Integration tests only
554
+ pytest tests/macro/
555
+
556
+ # Specific module
557
+ pytest tests/micro/agent/
558
+ pytest tests/micro/api/
559
+ ```
560
+
561
+ ---
562
+
563
+ ## Full Example
564
+
565
+ ```python
566
+ from agentsflow.dev import (
567
+ create_project, create_agent, add_tool,
568
+ add_preprocess, edit_preprocess, validate_agent, get_all_agents,
569
+ )
570
+ from agentsflow.schema.agent_config_schema import AgentModelConfig, Prompt
571
+ from agentsflow.schema.tool_config_schema import ToolIdentityConfig, ToolConfig
572
+
573
+ # 1. Set up project
574
+ create_project("Financial Analysis", dev_path="/home/user/fin_project", dev_env_strategy="project_local")
575
+
576
+ # 2. Create agent
577
+ create_agent(
578
+ base_dir="/home/user/fin_project",
579
+ agent_name="analyst",
580
+ model_config=AgentModelConfig(model="gpt-4o", temperature=0.2),
581
+ description="Financial research and analysis agent",
582
+ prompts=Prompt(
583
+ instruction="""You are a financial analyst.
584
+ Use available tools to research companies and calculate metrics.
585
+ Always show your reasoning.""",
586
+ think="Break analysis into: data gathering → calculation → conclusion",
587
+ ),
588
+ )
589
+
590
+ # 3. Add tool (script stored at tools/custom_tools/<name>/tool.py)
591
+ add_tool(
592
+ base_dir="/home/user/fin_project",
593
+ script="def get_stock_data(ticker: str):\n return {}",
594
+ identity=ToolIdentityConfig(name="stock_lookup", description="Get stock price and metrics", category="finance"),
595
+ config=ToolConfig(
596
+ function_name="get_stock_data",
597
+ parameters={"ticker": {"type": "string", "description": "Stock ticker (AAPL, MSFT)", "required": True}},
598
+ returns={"type": "object", "description": "Stock data"},
599
+ ),
600
+ agent_name="analyst",
601
+ )
602
+
603
+ # 4. Add preprocess (creates default script), then edit its content
604
+ add_preprocess("/home/user/fin_project", agent_name="analyst")
605
+ edit_preprocess("/home/user/fin_project", agent_name="analyst", script="def preprocess(prompt: str):\n return prompt.strip()")
606
+
607
+ # 5. Validate
608
+ validate_agent("/home/user/fin_project", agent_name="analyst")
609
+
610
+ # 6. List all agents
611
+ agents = get_all_agents("/home/user/fin_project")
612
+ # [AgentConfig(...)]
613
+ ```
614
+
615
+ Then in production:
616
+
617
+ ```python
618
+ from agentsflow import load_agents
619
+
620
+ agents = load_agents("/home/user/fin_project", env_path="/home/user/.env")
621
+ result = agents["analyst"].run("Analyze Apple's Q4 earnings and compare to Microsoft")
622
+ print(result.output)
623
+ ```