kodeagent 0.1.0__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.
- kodeagent-0.1.0/LICENSE +202 -0
- kodeagent-0.1.0/PKG-INFO +215 -0
- kodeagent-0.1.0/README.md +186 -0
- kodeagent-0.1.0/pyproject.toml +38 -0
- kodeagent-0.1.0/requirements.txt +20 -0
- kodeagent-0.1.0/setup.cfg +4 -0
- kodeagent-0.1.0/src/kodeagent/__init__.py +73 -0
- kodeagent-0.1.0/src/kodeagent/kodeagent.py +1984 -0
- kodeagent-0.1.0/src/kodeagent/kutils.py +298 -0
- kodeagent-0.1.0/src/kodeagent/prompts/agent_plan.txt +17 -0
- kodeagent-0.1.0/src/kodeagent/prompts/contextual_summary.txt +14 -0
- kodeagent-0.1.0/src/kodeagent/prompts/observation.txt +46 -0
- kodeagent-0.1.0/src/kodeagent/prompts/relevant_tools.txt +16 -0
- kodeagent-0.1.0/src/kodeagent/prompts/salvage_response.txt +14 -0
- kodeagent-0.1.0/src/kodeagent/prompts/update_plan.txt +20 -0
- kodeagent-0.1.0/src/kodeagent.egg-info/PKG-INFO +215 -0
- kodeagent-0.1.0/src/kodeagent.egg-info/SOURCES.txt +18 -0
- kodeagent-0.1.0/src/kodeagent.egg-info/dependency_links.txt +1 -0
- kodeagent-0.1.0/src/kodeagent.egg-info/requires.txt +14 -0
- kodeagent-0.1.0/src/kodeagent.egg-info/top_level.txt +1 -0
kodeagent-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
kodeagent-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kodeagent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A minimalistic approach to building AI agents
|
|
5
|
+
Author-email: Barun Saha <your.email@example.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/barun-saha/kodeagent
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/barun-saha/kodeagent/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: litellm~=1.75.7
|
|
15
|
+
Requires-Dist: pydantic~=2.11.3
|
|
16
|
+
Requires-Dist: python-dotenv~=1.1.0
|
|
17
|
+
Requires-Dist: e2b-code-interpreter~=1.5.2
|
|
18
|
+
Requires-Dist: requests~=2.32.3
|
|
19
|
+
Requires-Dist: json_repair~=0.49.0
|
|
20
|
+
Requires-Dist: tenacity~=8.3.0
|
|
21
|
+
Requires-Dist: rich~=14.1.0
|
|
22
|
+
Requires-Dist: ddgs~=9.5.2
|
|
23
|
+
Requires-Dist: markitdown[docx,pdf,xlsx]
|
|
24
|
+
Requires-Dist: youtube-transcript-api~=1.2.2
|
|
25
|
+
Requires-Dist: wikipedia~=1.4.0
|
|
26
|
+
Requires-Dist: arxiv~=2.2.0
|
|
27
|
+
Requires-Dist: langfuse<3,>=2
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# π€ KodeAgent
|
|
31
|
+
|
|
32
|
+
KodeAgent: A minimalistic approach to building AI agents.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## β
Why KodeAgent?
|
|
36
|
+
|
|
37
|
+
Here are some reasons why you should use KodeAgent:
|
|
38
|
+
|
|
39
|
+
- **Framework-less**: Unlike some heavy agentic frameworks, KodeAgent stays lightweight, making it easy to integrate and extend.
|
|
40
|
+
- **Learn-first design**: Helps developers understand agent-building from scratch.
|
|
41
|
+
- **Multimodal**: Supports both text and images in the inputs.
|
|
42
|
+
|
|
43
|
+
Written in about 2000 lines (excluding the prompts), KodeAgent comes with built-in ReAct and CodeAct agents. Or you can create your own agent by subclassing `Agent`.
|
|
44
|
+
|
|
45
|
+
A key motivation beyond KodeAgent is also to teach building agentic frameworks from scratch. KodeAgent introduces a few primitives and code flows that should help you to get an idea about how such frameworks typically work.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## β Why Not?
|
|
49
|
+
|
|
50
|
+
Also, here are a few reasons why you shouldn't use KodeAgent:
|
|
51
|
+
|
|
52
|
+
- KodeAgent is actively evolving, meaning some aspects may change.
|
|
53
|
+
- The first priority is simplicity; optimization is secondary.
|
|
54
|
+
- You already use some of the well-known frameworks or want to use them.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## π¨βπ» Usage
|
|
58
|
+
|
|
59
|
+
Clone the KodeAgent GitHub repository locally:
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://github.com/barun-saha/kodeagent.git
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Next, create a virtual environment if you do not have one already and activate it:
|
|
65
|
+
```bash
|
|
66
|
+
python -m venv venv
|
|
67
|
+
source venv/bin/activate
|
|
68
|
+
# venv\Scripts\activate.bat # Windows
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
KodeAgent has only a few direct dependencies. Install them as follows:
|
|
72
|
+
```bash
|
|
73
|
+
pip install -r requirements.txt
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Now, in your application code, create a ReAct agent like this:
|
|
77
|
+
```python
|
|
78
|
+
from kodeagent import ReActAgent
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
agent = ReActAgent(
|
|
82
|
+
name='Maths agent',
|
|
83
|
+
model_name='gemini/gemini-2.0-flash-lite',
|
|
84
|
+
tools=[calculator],
|
|
85
|
+
max_iterations=3,
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or if you want to use CodeAct agent:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from kodeagent import CodeActAgent
|
|
93
|
+
|
|
94
|
+
agent = CodeActAgent(
|
|
95
|
+
name='Web agent',
|
|
96
|
+
model_name='gemini/gemini-2.0-flash-lite',
|
|
97
|
+
tools=[search_web, extract_file_contents_as_markdown],
|
|
98
|
+
run_env='e2b',
|
|
99
|
+
max_iterations=3,
|
|
100
|
+
allowed_imports=['re', 'requests', 'duckduckgo_search', 'markitdown'],
|
|
101
|
+
pip_packages='ddgs~=9.5.2;"markitdown[all]";',
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Now let your agent solve the tasks like this:
|
|
106
|
+
```python
|
|
107
|
+
for task in [
|
|
108
|
+
'What is 10 + 15, raised to 2, expressed in words?',
|
|
109
|
+
]:
|
|
110
|
+
print(f'User: {task}')
|
|
111
|
+
|
|
112
|
+
async for response in agent.run(task):
|
|
113
|
+
print_response(response)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
That's it! Your agent should start solving the task and keep streaming the updates. For more examples, including how to provide files as inputs, see the [kodeagent.py](kodeagent.py) module.
|
|
117
|
+
|
|
118
|
+
KodeAgent uses [LiteLLM](https://github.com/BerriAI/litellm), enabling it to work with any capable LLM. Currently, KodeAgent has been tested with Gemini 2.5 Flash Lite. For advanced tasks, you can try Gemini 2.5 Pro.
|
|
119
|
+
|
|
120
|
+
LLM model names, parameters, and keys should be set as per [LiteLLM documentation](https://docs.litellm.ai/docs/set_keys). For example, add `GEMINI_API_KEY` to the `.env` to use Gemini API.
|
|
121
|
+
|
|
122
|
+
### Code Execution
|
|
123
|
+
|
|
124
|
+
`CodeActAgent` executes LLM-generated code to leverage the tools. KodeAgent currently supports two different code run environments:
|
|
125
|
+
- `host`: The Python code will be run on the system where you created this agent. In other words, where the application is running.
|
|
126
|
+
- `e2b`: The Python code will be run on an [E2B sandbox](https://e2b.dev/). You will need an E2B API key and add to your `.env` file.
|
|
127
|
+
|
|
128
|
+
With `host` as the code running environment, no special steps are required, since it uses the current Python installation. However, with `e2b`, code (and tools) are copied to a different environment and execute. Therefore, some additional set up may be required.
|
|
129
|
+
|
|
130
|
+
For example, the Python modules that are allowed to be used in code should be explicitly specified using `allowed_imports`. In addition, any additional Python package that may need to be installed should be specified as a comma-separated list via `pip_packages`.
|
|
131
|
+
|
|
132
|
+
KodeAgent is very much experimental. Capabilities are limited. Use with caution.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
## Sequence Diagram for CodeAct Agent (via CodeRabbit)
|
|
136
|
+
```mermaid
|
|
137
|
+
sequenceDiagram
|
|
138
|
+
autonumber
|
|
139
|
+
actor User
|
|
140
|
+
participant Agent
|
|
141
|
+
participant Planner
|
|
142
|
+
participant LLM as LLM/Prompts
|
|
143
|
+
participant Tools
|
|
144
|
+
|
|
145
|
+
User->>Agent: run(task)
|
|
146
|
+
Agent->>Planner: create_plan(task)
|
|
147
|
+
Planner->>LLM: request AgentPlan JSON (agent_plan.txt)
|
|
148
|
+
LLM-->>Planner: AgentPlan JSON
|
|
149
|
+
Planner-->>Agent: planner.plan set
|
|
150
|
+
|
|
151
|
+
loop For each step
|
|
152
|
+
Agent->>Planner: get_formatted_plan()
|
|
153
|
+
Agent->>LLM: codeact prompt + {plan, history}
|
|
154
|
+
LLM-->>Agent: Thought + Code
|
|
155
|
+
Agent->>Tools: execute tool call(s)
|
|
156
|
+
Tools-->>Agent: Observation
|
|
157
|
+
Agent->>Planner: update_plan(thought, observation, task_id)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
Agent-->>User: Final Answer / Failure (per codeact spec)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# Run Tests
|
|
165
|
+
|
|
166
|
+
To run unit tests, use:
|
|
167
|
+
```bash
|
|
168
|
+
python -m pytest .\tests\unit -v --cov --cov-report=html
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The current test coverage is 86%, on average.
|
|
172
|
+
|
|
173
|
+
For integration tests involving calls to APIs, use:
|
|
174
|
+
```bash
|
|
175
|
+
python -m pytest .\tests\integration -v --cov --cov-report=html
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Gemini and E2B API keys should be set in the `.env` file for integration tests to work.
|
|
179
|
+
|
|
180
|
+
A [Kaggle notebook](https://www.kaggle.com/code/barunsaha/kodeagent-benchmark/) for benchmarking KodeAgent is also available.
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
## π Publishing to PyPI
|
|
184
|
+
|
|
185
|
+
This project uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/using-a-publisher/) to automatically publish to PyPI when a new release is created on GitHub. To set this up, follow these steps:
|
|
186
|
+
|
|
187
|
+
1. **Configure Trusted Publisher on PyPI:**
|
|
188
|
+
* Log in to your PyPI account and go to the "Publishing" page for the `kodeagent` package.
|
|
189
|
+
* Add a new "Trusted Publisher" with the following settings:
|
|
190
|
+
* **Owner:** The GitHub organization or username that owns the repository (e.g., `barun-saha`).
|
|
191
|
+
* **Repository name:** `kodeagent`
|
|
192
|
+
* **Workflow name:** `publish-to-pypi.yml`
|
|
193
|
+
|
|
194
|
+
2. **Create a New Release on GitHub:**
|
|
195
|
+
* Go to the "Releases" page in your GitHub repository and click "Draft a new release".
|
|
196
|
+
* Create a new tag for the release (e.g., `v0.0.1`).
|
|
197
|
+
* Add a title and description for the release.
|
|
198
|
+
* Click "Publish release".
|
|
199
|
+
|
|
200
|
+
Once the release is published, the GitHub Actions workflow will automatically build the package and upload it to PyPI.
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## πΊοΈ Roadmap & Contributions
|
|
204
|
+
|
|
205
|
+
To be updated.
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
## π Acknowledgement
|
|
209
|
+
|
|
210
|
+
KodeAgent heavily borrows code and ideas from different places, such as:
|
|
211
|
+
- [LlamaIndex](https://docs.llamaindex.ai/en/stable/examples/agent/react_agent/)
|
|
212
|
+
- [Smolagents](https://github.com/huggingface/smolagents/tree/main)
|
|
213
|
+
- [LangGraph](https://github.com/langchain-ai/langgraph)
|
|
214
|
+
- [Building ReAct Agents from Scratch: A Hands-On Guide using Gemini](https://medium.com/google-cloud/building-react-agents-from-scratch-a-hands-on-guide-using-gemini-ffe4621d90ae)
|
|
215
|
+
- [LangGraph Tutorial: Build Your Own AI Coding Agent](https://medium.com/@mariumaslam499/build-your-own-ai-coding-agent-with-langgraph-040644343e73)
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# π€ KodeAgent
|
|
2
|
+
|
|
3
|
+
KodeAgent: A minimalistic approach to building AI agents.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## β
Why KodeAgent?
|
|
7
|
+
|
|
8
|
+
Here are some reasons why you should use KodeAgent:
|
|
9
|
+
|
|
10
|
+
- **Framework-less**: Unlike some heavy agentic frameworks, KodeAgent stays lightweight, making it easy to integrate and extend.
|
|
11
|
+
- **Learn-first design**: Helps developers understand agent-building from scratch.
|
|
12
|
+
- **Multimodal**: Supports both text and images in the inputs.
|
|
13
|
+
|
|
14
|
+
Written in about 2000 lines (excluding the prompts), KodeAgent comes with built-in ReAct and CodeAct agents. Or you can create your own agent by subclassing `Agent`.
|
|
15
|
+
|
|
16
|
+
A key motivation beyond KodeAgent is also to teach building agentic frameworks from scratch. KodeAgent introduces a few primitives and code flows that should help you to get an idea about how such frameworks typically work.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## β Why Not?
|
|
20
|
+
|
|
21
|
+
Also, here are a few reasons why you shouldn't use KodeAgent:
|
|
22
|
+
|
|
23
|
+
- KodeAgent is actively evolving, meaning some aspects may change.
|
|
24
|
+
- The first priority is simplicity; optimization is secondary.
|
|
25
|
+
- You already use some of the well-known frameworks or want to use them.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## π¨βπ» Usage
|
|
29
|
+
|
|
30
|
+
Clone the KodeAgent GitHub repository locally:
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/barun-saha/kodeagent.git
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Next, create a virtual environment if you do not have one already and activate it:
|
|
36
|
+
```bash
|
|
37
|
+
python -m venv venv
|
|
38
|
+
source venv/bin/activate
|
|
39
|
+
# venv\Scripts\activate.bat # Windows
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
KodeAgent has only a few direct dependencies. Install them as follows:
|
|
43
|
+
```bash
|
|
44
|
+
pip install -r requirements.txt
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Now, in your application code, create a ReAct agent like this:
|
|
48
|
+
```python
|
|
49
|
+
from kodeagent import ReActAgent
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
agent = ReActAgent(
|
|
53
|
+
name='Maths agent',
|
|
54
|
+
model_name='gemini/gemini-2.0-flash-lite',
|
|
55
|
+
tools=[calculator],
|
|
56
|
+
max_iterations=3,
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Or if you want to use CodeAct agent:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from kodeagent import CodeActAgent
|
|
64
|
+
|
|
65
|
+
agent = CodeActAgent(
|
|
66
|
+
name='Web agent',
|
|
67
|
+
model_name='gemini/gemini-2.0-flash-lite',
|
|
68
|
+
tools=[search_web, extract_file_contents_as_markdown],
|
|
69
|
+
run_env='e2b',
|
|
70
|
+
max_iterations=3,
|
|
71
|
+
allowed_imports=['re', 'requests', 'duckduckgo_search', 'markitdown'],
|
|
72
|
+
pip_packages='ddgs~=9.5.2;"markitdown[all]";',
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Now let your agent solve the tasks like this:
|
|
77
|
+
```python
|
|
78
|
+
for task in [
|
|
79
|
+
'What is 10 + 15, raised to 2, expressed in words?',
|
|
80
|
+
]:
|
|
81
|
+
print(f'User: {task}')
|
|
82
|
+
|
|
83
|
+
async for response in agent.run(task):
|
|
84
|
+
print_response(response)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
That's it! Your agent should start solving the task and keep streaming the updates. For more examples, including how to provide files as inputs, see the [kodeagent.py](kodeagent.py) module.
|
|
88
|
+
|
|
89
|
+
KodeAgent uses [LiteLLM](https://github.com/BerriAI/litellm), enabling it to work with any capable LLM. Currently, KodeAgent has been tested with Gemini 2.5 Flash Lite. For advanced tasks, you can try Gemini 2.5 Pro.
|
|
90
|
+
|
|
91
|
+
LLM model names, parameters, and keys should be set as per [LiteLLM documentation](https://docs.litellm.ai/docs/set_keys). For example, add `GEMINI_API_KEY` to the `.env` to use Gemini API.
|
|
92
|
+
|
|
93
|
+
### Code Execution
|
|
94
|
+
|
|
95
|
+
`CodeActAgent` executes LLM-generated code to leverage the tools. KodeAgent currently supports two different code run environments:
|
|
96
|
+
- `host`: The Python code will be run on the system where you created this agent. In other words, where the application is running.
|
|
97
|
+
- `e2b`: The Python code will be run on an [E2B sandbox](https://e2b.dev/). You will need an E2B API key and add to your `.env` file.
|
|
98
|
+
|
|
99
|
+
With `host` as the code running environment, no special steps are required, since it uses the current Python installation. However, with `e2b`, code (and tools) are copied to a different environment and execute. Therefore, some additional set up may be required.
|
|
100
|
+
|
|
101
|
+
For example, the Python modules that are allowed to be used in code should be explicitly specified using `allowed_imports`. In addition, any additional Python package that may need to be installed should be specified as a comma-separated list via `pip_packages`.
|
|
102
|
+
|
|
103
|
+
KodeAgent is very much experimental. Capabilities are limited. Use with caution.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Sequence Diagram for CodeAct Agent (via CodeRabbit)
|
|
107
|
+
```mermaid
|
|
108
|
+
sequenceDiagram
|
|
109
|
+
autonumber
|
|
110
|
+
actor User
|
|
111
|
+
participant Agent
|
|
112
|
+
participant Planner
|
|
113
|
+
participant LLM as LLM/Prompts
|
|
114
|
+
participant Tools
|
|
115
|
+
|
|
116
|
+
User->>Agent: run(task)
|
|
117
|
+
Agent->>Planner: create_plan(task)
|
|
118
|
+
Planner->>LLM: request AgentPlan JSON (agent_plan.txt)
|
|
119
|
+
LLM-->>Planner: AgentPlan JSON
|
|
120
|
+
Planner-->>Agent: planner.plan set
|
|
121
|
+
|
|
122
|
+
loop For each step
|
|
123
|
+
Agent->>Planner: get_formatted_plan()
|
|
124
|
+
Agent->>LLM: codeact prompt + {plan, history}
|
|
125
|
+
LLM-->>Agent: Thought + Code
|
|
126
|
+
Agent->>Tools: execute tool call(s)
|
|
127
|
+
Tools-->>Agent: Observation
|
|
128
|
+
Agent->>Planner: update_plan(thought, observation, task_id)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
Agent-->>User: Final Answer / Failure (per codeact spec)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# Run Tests
|
|
136
|
+
|
|
137
|
+
To run unit tests, use:
|
|
138
|
+
```bash
|
|
139
|
+
python -m pytest .\tests\unit -v --cov --cov-report=html
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The current test coverage is 86%, on average.
|
|
143
|
+
|
|
144
|
+
For integration tests involving calls to APIs, use:
|
|
145
|
+
```bash
|
|
146
|
+
python -m pytest .\tests\integration -v --cov --cov-report=html
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Gemini and E2B API keys should be set in the `.env` file for integration tests to work.
|
|
150
|
+
|
|
151
|
+
A [Kaggle notebook](https://www.kaggle.com/code/barunsaha/kodeagent-benchmark/) for benchmarking KodeAgent is also available.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
## π Publishing to PyPI
|
|
155
|
+
|
|
156
|
+
This project uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/using-a-publisher/) to automatically publish to PyPI when a new release is created on GitHub. To set this up, follow these steps:
|
|
157
|
+
|
|
158
|
+
1. **Configure Trusted Publisher on PyPI:**
|
|
159
|
+
* Log in to your PyPI account and go to the "Publishing" page for the `kodeagent` package.
|
|
160
|
+
* Add a new "Trusted Publisher" with the following settings:
|
|
161
|
+
* **Owner:** The GitHub organization or username that owns the repository (e.g., `barun-saha`).
|
|
162
|
+
* **Repository name:** `kodeagent`
|
|
163
|
+
* **Workflow name:** `publish-to-pypi.yml`
|
|
164
|
+
|
|
165
|
+
2. **Create a New Release on GitHub:**
|
|
166
|
+
* Go to the "Releases" page in your GitHub repository and click "Draft a new release".
|
|
167
|
+
* Create a new tag for the release (e.g., `v0.0.1`).
|
|
168
|
+
* Add a title and description for the release.
|
|
169
|
+
* Click "Publish release".
|
|
170
|
+
|
|
171
|
+
Once the release is published, the GitHub Actions workflow will automatically build the package and upload it to PyPI.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## πΊοΈ Roadmap & Contributions
|
|
175
|
+
|
|
176
|
+
To be updated.
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
## π Acknowledgement
|
|
180
|
+
|
|
181
|
+
KodeAgent heavily borrows code and ideas from different places, such as:
|
|
182
|
+
- [LlamaIndex](https://docs.llamaindex.ai/en/stable/examples/agent/react_agent/)
|
|
183
|
+
- [Smolagents](https://github.com/huggingface/smolagents/tree/main)
|
|
184
|
+
- [LangGraph](https://github.com/langchain-ai/langgraph)
|
|
185
|
+
- [Building ReAct Agents from Scratch: A Hands-On Guide using Gemini](https://medium.com/google-cloud/building-react-agents-from-scratch-a-hands-on-guide-using-gemini-ffe4621d90ae)
|
|
186
|
+
- [LangGraph Tutorial: Build Your Own AI Coding Agent](https://medium.com/@mariumaslam499/build-your-own-ai-coding-agent-with-langgraph-040644343e73)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "kodeagent"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Barun Saha", email="your.email@example.com" }
|
|
10
|
+
]
|
|
11
|
+
description = "A minimalistic approach to building AI agents "
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dynamic = ["dependencies"]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
package-dir = {"" = "src"}
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.dynamic]
|
|
28
|
+
dependencies = {file = ["requirements.txt"]}
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.package-data]
|
|
31
|
+
kodeagent = ["prompts/*.txt"]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
pythonpath = "src"
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
"Homepage" = "https://github.com/barun-saha/kodeagent"
|
|
38
|
+
"Bug Tracker" = "https://github.com/barun-saha/kodeagent/issues"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
litellm~=1.75.7
|
|
2
|
+
pydantic~=2.11.3
|
|
3
|
+
python-dotenv~=1.1.0
|
|
4
|
+
e2b-code-interpreter~=1.5.2
|
|
5
|
+
requests~=2.32.3
|
|
6
|
+
json_repair~=0.49.0
|
|
7
|
+
tenacity~=8.3.0
|
|
8
|
+
|
|
9
|
+
# Dependency for colored display on terminals
|
|
10
|
+
rich~=14.1.0
|
|
11
|
+
|
|
12
|
+
# Dependencies for the tools
|
|
13
|
+
ddgs~=9.5.2
|
|
14
|
+
markitdown[pdf, docx, xlsx]
|
|
15
|
+
youtube-transcript-api~=1.2.2
|
|
16
|
+
wikipedia~=1.4.0
|
|
17
|
+
arxiv~=2.2.0
|
|
18
|
+
|
|
19
|
+
# Observability
|
|
20
|
+
langfuse>=2,<3
|