pyagentic-core 2.2.1a1__tar.gz → 2.2.2__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.
Files changed (45) hide show
  1. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/PKG-INFO +1 -1
  2. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_agent/_agent.py +28 -8
  3. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_agent/_agent_state.py +9 -6
  4. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic_core.egg-info/PKG-INFO +1 -1
  5. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyproject.toml +1 -1
  6. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/LICENSE +0 -0
  7. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/README.md +0 -0
  8. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/__init__.py +0 -0
  9. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/__init__.py +0 -0
  10. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_agent/__init__.py +0 -0
  11. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_agent/_agent_linking.py +0 -0
  12. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_exceptions.py +0 -0
  13. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_info.py +0 -0
  14. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_metaclasses.py +0 -0
  15. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_ref.py +0 -0
  16. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_spec.py +0 -0
  17. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_state.py +0 -0
  18. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_tool.py +0 -0
  19. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_base/_validation.py +0 -0
  20. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_utils/_typing.py +0 -0
  21. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/_utils/_warnings.py +0 -0
  22. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/__init__.py +0 -0
  23. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/_anthropic.py +0 -0
  24. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/_gemini.py +0 -0
  25. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/_mock.py +0 -0
  26. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/_openai.py +0 -0
  27. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/_openaiv1.py +0 -0
  28. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/llm/_provider.py +0 -0
  29. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/logging.py +0 -0
  30. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/models/llm.py +0 -0
  31. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/models/response.py +0 -0
  32. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/models/tracing.py +0 -0
  33. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/policies/__init__.py +0 -0
  34. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/policies/_events.py +0 -0
  35. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/policies/_policy.py +0 -0
  36. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/tracing/__init__.py +0 -0
  37. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/tracing/_basic.py +0 -0
  38. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/tracing/_langfuse.py +0 -0
  39. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/tracing/_tracer.py +0 -0
  40. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic/updates.py +0 -0
  41. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic_core.egg-info/SOURCES.txt +0 -0
  42. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic_core.egg-info/dependency_links.txt +0 -0
  43. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic_core.egg-info/requires.txt +0 -0
  44. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/pyagentic_core.egg-info/top_level.txt +0 -0
  45. {pyagentic_core-2.2.1a1 → pyagentic_core-2.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyagentic-core
3
- Version: 2.2.1a1
3
+ Version: 2.2.2
4
4
  Summary: Build LLM Agents in a Pythonic way
5
5
  Author-email: Ryan Mikulec <rmikulec.dev@gmail.com>
6
6
  License: MIT
@@ -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
- # Execute all tool/agent calls from this response
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
- result = await self._process_tool_call(tool_call, call_depth=depth)
574
- tool_responses.append(result)
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
- result = await self._process_agent_call(tool_call)
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
- yield result
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
@@ -61,15 +60,18 @@ class _AgentState(BaseModel):
61
60
  self._machine = machine
62
61
 
63
62
  def _update_state_machine(self, phases):
64
- for to_, from_, condition in phases:
65
- if condition(self):
66
- trigger = f"{to_}_to_{from_}"
67
- getattr(self._machine, trigger)()
63
+ for source, dest, condition in phases:
64
+ with self._state_lock:
65
+ if condition(self) and self.phase == source:
66
+ trigger = f"{source}_to_{dest}"
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
- setattr(self, name, final_value)
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyagentic-core
3
- Version: 2.2.1a1
3
+ Version: 2.2.2
4
4
  Summary: Build LLM Agents in a Pythonic way
5
5
  Author-email: Ryan Mikulec <rmikulec.dev@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyagentic-core"
3
- version = "2.2.1-a.1"
3
+ version = "2.2.2"
4
4
  description = "Build LLM Agents in a Pythonic way"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
File without changes