pyagentic-core 2.2.0__tar.gz → 2.2.0a2__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.0 → pyagentic_core-2.2.0a2}/PKG-INFO +1 -1
  2. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_agent/_agent.py +28 -8
  3. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_agent/_agent_state.py +8 -5
  4. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic_core.egg-info/PKG-INFO +1 -1
  5. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyproject.toml +1 -1
  6. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/LICENSE +0 -0
  7. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/README.md +0 -0
  8. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/__init__.py +0 -0
  9. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/__init__.py +0 -0
  10. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_agent/__init__.py +0 -0
  11. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_agent/_agent_linking.py +0 -0
  12. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_exceptions.py +0 -0
  13. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_info.py +0 -0
  14. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_metaclasses.py +0 -0
  15. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_ref.py +0 -0
  16. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_spec.py +0 -0
  17. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_state.py +0 -0
  18. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_tool.py +0 -0
  19. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_base/_validation.py +0 -0
  20. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_utils/_typing.py +0 -0
  21. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/_utils/_warnings.py +0 -0
  22. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/__init__.py +0 -0
  23. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/_anthropic.py +0 -0
  24. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/_gemini.py +0 -0
  25. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/_mock.py +0 -0
  26. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/_openai.py +0 -0
  27. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/_openaiv1.py +0 -0
  28. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/llm/_provider.py +0 -0
  29. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/logging.py +0 -0
  30. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/models/llm.py +0 -0
  31. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/models/response.py +0 -0
  32. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/models/tracing.py +0 -0
  33. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/policies/__init__.py +0 -0
  34. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/policies/_events.py +0 -0
  35. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/policies/_policy.py +0 -0
  36. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/tracing/__init__.py +0 -0
  37. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/tracing/_basic.py +0 -0
  38. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/tracing/_langfuse.py +0 -0
  39. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/tracing/_tracer.py +0 -0
  40. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic/updates.py +0 -0
  41. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic_core.egg-info/SOURCES.txt +0 -0
  42. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic_core.egg-info/dependency_links.txt +0 -0
  43. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic_core.egg-info/requires.txt +0 -0
  44. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/pyagentic_core.egg-info/top_level.txt +0 -0
  45. {pyagentic_core-2.2.0 → pyagentic_core-2.2.0a2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyagentic-core
3
- Version: 2.2.0
3
+ Version: 2.2.0a2
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,
@@ -548,24 +549,43 @@ class BaseAgent(metaclass=AgentMeta):
548
549
  self.state._messages.append(Message(role="assistant", content=response.text))
549
550
  break
550
551
 
551
- # Execute all tool/agent calls from this response
552
+ tasks = []
553
+
554
+ async def wrap(kind: str, tool_call, coro):
555
+ """Run the coroutine and attach metadata."""
556
+ result = await coro
557
+ return kind, tool_call, result
558
+
552
559
  for tool_call in response.tool_calls:
553
- # Skip if we've already processed this call (prevents duplicates)
554
560
  if tool_call.id and tool_call.id in processed_call_ids:
555
561
  continue
556
562
 
557
563
  processed_call_ids.add(tool_call.id)
558
564
 
559
- # Route to either @tool methods or linked agents
560
565
  if tool_call.name in self.__tool_defs__:
561
- result = await self._process_tool_call(tool_call, call_depth=depth)
562
- tool_responses.append(result)
563
- yield result
566
+ coro = self._process_tool_call(tool_call, call_depth=depth)
567
+ kind = "tool"
564
568
 
565
569
  elif tool_call.name in self.__linked_agents__:
566
- result = await self._process_agent_call(tool_call)
570
+ coro = self._process_agent_call(tool_call)
571
+ kind = "agent"
572
+
573
+ else:
574
+ continue
575
+
576
+ task = asyncio.create_task(wrap(kind, tool_call, coro))
577
+ tasks.append(task)
578
+
579
+ # Process tasks as they *finish*, not in original order
580
+ for task in asyncio.as_completed(tasks):
581
+ kind, tool_call, result = await task
582
+
583
+ if kind == "tool":
584
+ tool_responses.append(result)
585
+ else:
567
586
  agent_responses.append(result)
568
- yield result
587
+
588
+ yield result
569
589
 
570
590
  # Increment depth and continue loop (LLM will see tool results next iteration)
571
591
  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
- if condition(self):
66
- trigger = f"{to_}_to_{from_}"
67
- getattr(self._machine, trigger)()
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
- 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.0
3
+ Version: 2.2.0a2
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.0"
3
+ version = "2.2.0-a.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