zrb 1.5.7__py3-none-any.whl → 1.5.9__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.
- zrb/builtin/llm/tool/rag.py +4 -3
- zrb/llm_config.py +38 -0
- zrb/task/any_task.py +22 -6
- zrb/task/base/__init__.py +0 -0
- zrb/task/base/context.py +108 -0
- zrb/task/base/dependencies.py +57 -0
- zrb/task/base/execution.py +274 -0
- zrb/task/base/lifecycle.py +182 -0
- zrb/task/base/monitoring.py +134 -0
- zrb/task/base/operators.py +41 -0
- zrb/task/base_task.py +76 -382
- zrb/task/cmd_task.py +2 -1
- zrb/task/llm/agent.py +141 -0
- zrb/task/llm/config.py +83 -0
- zrb/task/llm/context.py +95 -0
- zrb/task/llm/{context_enricher.py → context_enrichment.py} +55 -6
- zrb/task/llm/history.py +153 -3
- zrb/task/llm/history_summarization.py +173 -0
- zrb/task/llm/prompt.py +87 -0
- zrb/task/llm/typing.py +3 -0
- zrb/task/llm_task.py +140 -323
- {zrb-1.5.7.dist-info → zrb-1.5.9.dist-info}/METADATA +2 -2
- {zrb-1.5.7.dist-info → zrb-1.5.9.dist-info}/RECORD +25 -15
- zrb/task/llm/agent_runner.py +0 -53
- zrb/task/llm/default_context.py +0 -45
- zrb/task/llm/history_summarizer.py +0 -71
- {zrb-1.5.7.dist-info → zrb-1.5.9.dist-info}/WHEEL +0 -0
- {zrb-1.5.7.dist-info → zrb-1.5.9.dist-info}/entry_points.txt +0 -0
zrb/task/llm/default_context.py
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
import datetime
|
2
|
-
import os
|
3
|
-
import platform
|
4
|
-
import re
|
5
|
-
from typing import Any
|
6
|
-
|
7
|
-
from zrb.util.file import read_dir, read_file_with_line_numbers
|
8
|
-
|
9
|
-
|
10
|
-
def get_default_context(user_message: str) -> dict[str, Any]:
|
11
|
-
references = re.findall(r"@(\S+)", user_message)
|
12
|
-
current_references = []
|
13
|
-
|
14
|
-
for ref in references:
|
15
|
-
resource_path = os.path.abspath(os.path.expanduser(ref))
|
16
|
-
if os.path.isfile(resource_path):
|
17
|
-
content = read_file_with_line_numbers(resource_path)
|
18
|
-
current_references.append(
|
19
|
-
{
|
20
|
-
"reference": ref,
|
21
|
-
"name": resource_path,
|
22
|
-
"type": "file",
|
23
|
-
"note": "line numbers are included in the content",
|
24
|
-
"content": content,
|
25
|
-
}
|
26
|
-
)
|
27
|
-
elif os.path.isdir(resource_path):
|
28
|
-
content = read_dir(resource_path)
|
29
|
-
current_references.append(
|
30
|
-
{
|
31
|
-
"reference": ref,
|
32
|
-
"name": resource_path,
|
33
|
-
"type": "directory",
|
34
|
-
"content": content,
|
35
|
-
}
|
36
|
-
)
|
37
|
-
|
38
|
-
return {
|
39
|
-
"current_time": datetime.datetime.now().isoformat(),
|
40
|
-
"current_working_directory": os.getcwd(),
|
41
|
-
"current_os": platform.system(),
|
42
|
-
"os_version": platform.version(),
|
43
|
-
"python_version": platform.python_version(),
|
44
|
-
"current_references": current_references,
|
45
|
-
}
|
@@ -1,71 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from typing import Any
|
3
|
-
|
4
|
-
from pydantic import BaseModel
|
5
|
-
from pydantic_ai import Agent
|
6
|
-
from pydantic_ai.models import Model
|
7
|
-
from pydantic_ai.settings import ModelSettings
|
8
|
-
|
9
|
-
from zrb.context.any_context import AnyContext
|
10
|
-
from zrb.task.llm.agent_runner import run_agent_iteration
|
11
|
-
from zrb.task.llm.history import ListOfDict
|
12
|
-
|
13
|
-
|
14
|
-
# Configuration model for history summarization
|
15
|
-
class SummarizationConfig(BaseModel):
|
16
|
-
model_config = {"arbitrary_types_allowed": True}
|
17
|
-
model: Model | str | None = None
|
18
|
-
settings: ModelSettings | None = None
|
19
|
-
prompt: str
|
20
|
-
retries: int = 1
|
21
|
-
|
22
|
-
|
23
|
-
async def summarize_history(
|
24
|
-
ctx: AnyContext,
|
25
|
-
config: SummarizationConfig,
|
26
|
-
conversation_context: dict[str, Any],
|
27
|
-
history_list: ListOfDict,
|
28
|
-
) -> dict[str, Any]:
|
29
|
-
"""Runs an LLM call to summarize history and update the context."""
|
30
|
-
ctx.log_info("Attempting to summarize conversation history...")
|
31
|
-
|
32
|
-
summarization_agent = Agent(
|
33
|
-
model=config.model,
|
34
|
-
system_prompt=config.prompt,
|
35
|
-
tools=[], # No tools needed for summarization
|
36
|
-
mcp_servers=[],
|
37
|
-
model_settings=config.settings,
|
38
|
-
retries=config.retries,
|
39
|
-
)
|
40
|
-
|
41
|
-
# Prepare context and history for summarization prompt
|
42
|
-
try:
|
43
|
-
context_json = json.dumps(conversation_context)
|
44
|
-
history_to_summarize_json = json.dumps(history_list)
|
45
|
-
summarization_user_prompt = (
|
46
|
-
f"# Current Context\n{context_json}\n\n"
|
47
|
-
f"# Conversation History to Summarize\n{history_to_summarize_json}"
|
48
|
-
)
|
49
|
-
except Exception as e:
|
50
|
-
ctx.log_warning(f"Error formatting context/history for summarization: {e}")
|
51
|
-
return conversation_context # Return original context if formatting fails
|
52
|
-
|
53
|
-
try:
|
54
|
-
summary_run = await run_agent_iteration(
|
55
|
-
ctx=ctx,
|
56
|
-
agent=summarization_agent,
|
57
|
-
user_prompt=summarization_user_prompt,
|
58
|
-
history_list=[], # Summarization agent doesn't need prior history
|
59
|
-
)
|
60
|
-
if summary_run and summary_run.result.data:
|
61
|
-
summary_text = str(summary_run.result.data)
|
62
|
-
# Update context with the new summary
|
63
|
-
conversation_context["history_summary"] = summary_text
|
64
|
-
ctx.log_info("History summarized and added/updated in context.")
|
65
|
-
ctx.log_info(f"Conversaion summary: {summary_text}")
|
66
|
-
else:
|
67
|
-
ctx.log_warning("History summarization failed or returned no data.")
|
68
|
-
except Exception as e:
|
69
|
-
ctx.log_warning(f"Error during history summarization: {e}")
|
70
|
-
|
71
|
-
return conversation_context
|
File without changes
|
File without changes
|