kader 0.1.5__py3-none-any.whl
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.
- cli/README.md +169 -0
- cli/__init__.py +5 -0
- cli/__main__.py +6 -0
- cli/app.py +707 -0
- cli/app.tcss +664 -0
- cli/utils.py +68 -0
- cli/widgets/__init__.py +13 -0
- cli/widgets/confirmation.py +309 -0
- cli/widgets/conversation.py +55 -0
- cli/widgets/loading.py +59 -0
- kader/__init__.py +22 -0
- kader/agent/__init__.py +8 -0
- kader/agent/agents.py +126 -0
- kader/agent/base.py +927 -0
- kader/agent/logger.py +170 -0
- kader/config.py +139 -0
- kader/memory/__init__.py +66 -0
- kader/memory/conversation.py +409 -0
- kader/memory/session.py +385 -0
- kader/memory/state.py +211 -0
- kader/memory/types.py +116 -0
- kader/prompts/__init__.py +9 -0
- kader/prompts/agent_prompts.py +27 -0
- kader/prompts/base.py +81 -0
- kader/prompts/templates/planning_agent.j2 +26 -0
- kader/prompts/templates/react_agent.j2 +18 -0
- kader/providers/__init__.py +9 -0
- kader/providers/base.py +581 -0
- kader/providers/mock.py +96 -0
- kader/providers/ollama.py +447 -0
- kader/tools/README.md +483 -0
- kader/tools/__init__.py +130 -0
- kader/tools/base.py +955 -0
- kader/tools/exec_commands.py +249 -0
- kader/tools/filesys.py +650 -0
- kader/tools/filesystem.py +607 -0
- kader/tools/protocol.py +456 -0
- kader/tools/rag.py +555 -0
- kader/tools/todo.py +210 -0
- kader/tools/utils.py +456 -0
- kader/tools/web.py +246 -0
- kader-0.1.5.dist-info/METADATA +321 -0
- kader-0.1.5.dist-info/RECORD +45 -0
- kader-0.1.5.dist-info/WHEEL +4 -0
- kader-0.1.5.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from .base import PromptBase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BasicAssistancePrompt(PromptBase):
|
|
8
|
+
"""Basic assistance prompt with date context."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
11
|
+
template = "You are a helpful AI assistant. Today is {{ date }}."
|
|
12
|
+
kwargs.setdefault("date", datetime.now().strftime("%Y-%m-%d"))
|
|
13
|
+
super().__init__(template=template, **kwargs)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ReActAgentPrompt(PromptBase):
|
|
17
|
+
"""Prompt for ReAct Agent."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
20
|
+
super().__init__(template_path="react_agent.j2", **kwargs)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PlanningAgentPrompt(PromptBase):
|
|
24
|
+
"""Prompt for Planning Agent."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
27
|
+
super().__init__(template_path="planning_agent.j2", **kwargs)
|
kader/prompts/base.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from jinja2 import Environment, FileSystemLoader
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PromptBase:
|
|
9
|
+
"""
|
|
10
|
+
Base class for handling Jinja2 templates for prompts.
|
|
11
|
+
|
|
12
|
+
Attributes
|
|
13
|
+
----------
|
|
14
|
+
template : str, optional
|
|
15
|
+
A string containing the Jinja2 template.
|
|
16
|
+
template_path : str, optional
|
|
17
|
+
The path to the Jinja2 template file.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
template: str | None = None
|
|
21
|
+
template_path: str | None = None
|
|
22
|
+
|
|
23
|
+
def __init__(self, **kwargs) -> None:
|
|
24
|
+
"""Initialize the PromptBase instance.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
**kwargs
|
|
29
|
+
Keyword arguments that will be available as variables in the template.
|
|
30
|
+
Special keys 'template' and 'template_path' are used to initialize the prompt.
|
|
31
|
+
"""
|
|
32
|
+
self.template = kwargs.pop("template", self.template)
|
|
33
|
+
self.template_path = kwargs.pop("template_path", self.template_path)
|
|
34
|
+
self.vars = kwargs
|
|
35
|
+
|
|
36
|
+
if self.template:
|
|
37
|
+
env = Environment()
|
|
38
|
+
self.prompt = env.from_string(self.template)
|
|
39
|
+
elif self.template_path:
|
|
40
|
+
current_dir = Path(__file__).parent
|
|
41
|
+
path = os.path.join(current_dir, "templates")
|
|
42
|
+
loader = FileSystemLoader(path)
|
|
43
|
+
env = Environment(loader=loader)
|
|
44
|
+
self.prompt = env.get_template(self.template_path)
|
|
45
|
+
self._resolved_prompt = None
|
|
46
|
+
|
|
47
|
+
def render_template(self) -> str:
|
|
48
|
+
"""Render the Jinja2 template with the provided variables.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
str
|
|
53
|
+
The rendered prompt as a string.
|
|
54
|
+
"""
|
|
55
|
+
render = self.prompt.render(**self.vars)
|
|
56
|
+
render = re.sub(r"\n{3,}", "\n\n", render)
|
|
57
|
+
return render
|
|
58
|
+
|
|
59
|
+
def resolve_prompt(self) -> str:
|
|
60
|
+
"""Resolve the prompt by rendering it if it hasn't been already.
|
|
61
|
+
|
|
62
|
+
This method ensures the template is rendered only once and the result is cached.
|
|
63
|
+
|
|
64
|
+
Returns
|
|
65
|
+
-------
|
|
66
|
+
str
|
|
67
|
+
The resolved prompt.
|
|
68
|
+
"""
|
|
69
|
+
if self._resolved_prompt is None:
|
|
70
|
+
self._resolved_prompt = self.render_template()
|
|
71
|
+
return self._resolved_prompt
|
|
72
|
+
|
|
73
|
+
def __str__(self) -> str:
|
|
74
|
+
"""Return the resolved prompt when the object is converted to a string.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
str
|
|
79
|
+
The resolved prompt.
|
|
80
|
+
"""
|
|
81
|
+
return self.resolve_prompt()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
You are a planning agent. You have access to the following tools:
|
|
2
|
+
|
|
3
|
+
{% for tool in tools %}
|
|
4
|
+
{{ tool.name }}: {{ tool.description }}
|
|
5
|
+
{% endfor %}
|
|
6
|
+
|
|
7
|
+
Your goal is to complete the user's request by creating a plan and executing it step-by-step.
|
|
8
|
+
|
|
9
|
+
Instructions:
|
|
10
|
+
1. Break down the user request into logical steps.
|
|
11
|
+
2. For each step, determine if a tool is needed.
|
|
12
|
+
3. Execute necessary tools.
|
|
13
|
+
4. CRITICAL: Always create a TODO Using TODO Tool for the logical.
|
|
14
|
+
5. CRITICAL: After completing a step (e.g., creating a file, running a test), you MUST immediately use the TODO Tool to update the status of that item to 'completed'. Do not proceed to the next item without updating the TODO list.
|
|
15
|
+
6. Planning Agent must use TODO Tool to ensure that the plan is completed when execution occurs.
|
|
16
|
+
7. If you have enough information, provide the final answer.
|
|
17
|
+
|
|
18
|
+
Example (programming task):
|
|
19
|
+
Task:
|
|
20
|
+
- Implement a ML Inference Endpoint.
|
|
21
|
+
Plan:
|
|
22
|
+
- Analyze the requirements and design the system architecture.
|
|
23
|
+
- Implement the endpoint using a web framework.
|
|
24
|
+
- Test the endpoint to ensure it works as expected.
|
|
25
|
+
- Deploy the endpoint to a production environment.
|
|
26
|
+
this requires going back and forth with the user and todo tools, and also using other tools to complete the task. You must update the todo list after each step.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Answer the following questions as best you can. You have access to the following tools:
|
|
2
|
+
|
|
3
|
+
{% for tool in tools %}
|
|
4
|
+
{{ tool.name }}: {{ tool.description }}
|
|
5
|
+
{% endfor %}
|
|
6
|
+
|
|
7
|
+
Use the following format:
|
|
8
|
+
|
|
9
|
+
Question: the input question you must answer
|
|
10
|
+
Thought: you should always think about what to do
|
|
11
|
+
Action: the action to take, should be one of [{{ tool_names }}]
|
|
12
|
+
Action Input: the input to the action
|
|
13
|
+
Observation: the result of the action
|
|
14
|
+
... (this Thought/Action/Action Input/Observation can repeat N times)
|
|
15
|
+
Thought: I now know the final answer
|
|
16
|
+
Final Answer: the final answer to the original input question
|
|
17
|
+
|
|
18
|
+
Begin!
|