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.
@@ -0,0 +1,9 @@
1
+ from .agent_prompts import BasicAssistancePrompt, PlanningAgentPrompt, ReActAgentPrompt
2
+ from .base import PromptBase
3
+
4
+ __all__ = [
5
+ "PromptBase",
6
+ "BasicAssistancePrompt",
7
+ "ReActAgentPrompt",
8
+ "PlanningAgentPrompt",
9
+ ]
@@ -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!
@@ -0,0 +1,9 @@
1
+ from .base import Message
2
+ from .mock import MockLLM
3
+ from .ollama import OllamaProvider
4
+
5
+ __all__ = [
6
+ "Message",
7
+ "OllamaProvider",
8
+ "MockLLM",
9
+ ]