pyagentic-core 2.2.1__tar.gz → 2.2.1a2__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.
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/PKG-INFO +1 -1
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_agent/_agent.py +28 -8
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_agent/_agent_state.py +8 -5
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic_core.egg-info/PKG-INFO +1 -1
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyproject.toml +1 -1
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/LICENSE +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/README.md +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/__init__.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/__init__.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_agent/__init__.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_agent/_agent_linking.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_exceptions.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_info.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_metaclasses.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_ref.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_spec.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_state.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_tool.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_base/_validation.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_utils/_typing.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/_utils/_warnings.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/__init__.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/_anthropic.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/_gemini.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/_mock.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/_openai.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/_openaiv1.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/llm/_provider.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/logging.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/models/llm.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/models/response.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/models/tracing.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/policies/__init__.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/policies/_events.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/policies/_policy.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/tracing/__init__.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/tracing/_basic.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/tracing/_langfuse.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/tracing/_tracer.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic/updates.py +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic_core.egg-info/SOURCES.txt +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic_core.egg-info/dependency_links.txt +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic_core.egg-info/requires.txt +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic_core.egg-info/top_level.txt +0 -0
- {pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/setup.cfg +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import json
|
|
3
|
+
import asyncio
|
|
3
4
|
from functools import wraps
|
|
4
5
|
from typing import (
|
|
5
6
|
Callable,
|
|
@@ -560,24 +561,43 @@ class BaseAgent(metaclass=AgentMeta):
|
|
|
560
561
|
self.state._messages.append(Message(role="assistant", content=response.text))
|
|
561
562
|
break
|
|
562
563
|
|
|
563
|
-
|
|
564
|
+
tasks = []
|
|
565
|
+
|
|
566
|
+
async def wrap(kind: str, tool_call, coro):
|
|
567
|
+
"""Run the coroutine and attach metadata."""
|
|
568
|
+
result = await coro
|
|
569
|
+
return kind, tool_call, result
|
|
570
|
+
|
|
564
571
|
for tool_call in response.tool_calls:
|
|
565
|
-
# Skip if we've already processed this call (prevents duplicates)
|
|
566
572
|
if tool_call.id and tool_call.id in processed_call_ids:
|
|
567
573
|
continue
|
|
568
574
|
|
|
569
575
|
processed_call_ids.add(tool_call.id)
|
|
570
576
|
|
|
571
|
-
# Route to either @tool methods or linked agents
|
|
572
577
|
if tool_call.name in self.__tool_defs__:
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
yield result
|
|
578
|
+
coro = self._process_tool_call(tool_call, call_depth=depth)
|
|
579
|
+
kind = "tool"
|
|
576
580
|
|
|
577
581
|
elif tool_call.name in self.__linked_agents__:
|
|
578
|
-
|
|
582
|
+
coro = self._process_agent_call(tool_call)
|
|
583
|
+
kind = "agent"
|
|
584
|
+
|
|
585
|
+
else:
|
|
586
|
+
continue
|
|
587
|
+
|
|
588
|
+
task = asyncio.create_task(wrap(kind, tool_call, coro))
|
|
589
|
+
tasks.append(task)
|
|
590
|
+
|
|
591
|
+
# Process tasks as they *finish*, not in original order
|
|
592
|
+
for task in asyncio.as_completed(tasks):
|
|
593
|
+
kind, tool_call, result = await task
|
|
594
|
+
|
|
595
|
+
if kind == "tool":
|
|
596
|
+
tool_responses.append(result)
|
|
597
|
+
else:
|
|
579
598
|
agent_responses.append(result)
|
|
580
|
-
|
|
599
|
+
|
|
600
|
+
yield result
|
|
581
601
|
|
|
582
602
|
# Increment depth and continue loop (LLM will see tool results next iteration)
|
|
583
603
|
depth += 1
|
|
@@ -26,7 +26,6 @@ class _AgentState(BaseModel):
|
|
|
26
26
|
("on", EventKind.SET): "on_set",
|
|
27
27
|
("background", EventKind.SET): "background_set",
|
|
28
28
|
}
|
|
29
|
-
_state_lock: ClassVar[threading.Lock] = PrivateAttr(default_factory=threading.Lock)
|
|
30
29
|
__policies__: ClassVar[dict[str, list[Policy]]]
|
|
31
30
|
|
|
32
31
|
instructions: str
|
|
@@ -62,14 +61,17 @@ class _AgentState(BaseModel):
|
|
|
62
61
|
|
|
63
62
|
def _update_state_machine(self, phases):
|
|
64
63
|
for to_, from_, condition in phases:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
with self._state_lock:
|
|
65
|
+
if condition(self) and self.phase == from_:
|
|
66
|
+
trigger = f"{to_}_to_{from_}"
|
|
67
|
+
getattr(self._machine, trigger)()
|
|
68
68
|
|
|
69
69
|
def model_post_init(self, state):
|
|
70
70
|
self._instructions_template = Template(source=self.instructions)
|
|
71
71
|
if self.input_template:
|
|
72
72
|
self._input_template = Template(source=self.input_template)
|
|
73
|
+
|
|
74
|
+
self._state_lock = threading.Lock()
|
|
73
75
|
return super().model_post_init(state)
|
|
74
76
|
|
|
75
77
|
def get_policies(self, state_name: str) -> list[Policy]:
|
|
@@ -208,7 +210,8 @@ class _AgentState(BaseModel):
|
|
|
208
210
|
event = SetEvent(name=name, previous=previous, value=value)
|
|
209
211
|
final_value = self._run_policies(event, "on")
|
|
210
212
|
|
|
211
|
-
|
|
213
|
+
with self._state_lock:
|
|
214
|
+
setattr(self, name, final_value)
|
|
212
215
|
asyncio.create_task(self._dispatch_policies(event, "background"))
|
|
213
216
|
|
|
214
217
|
@classmethod
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyagentic_core-2.2.1 → pyagentic_core-2.2.1a2}/pyagentic_core.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|