zrb 1.5.7__py3-none-any.whl → 1.5.8__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.
@@ -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