langroid 0.56.2__py3-none-any.whl → 0.56.4__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.
- langroid/agent/base.py +25 -12
- langroid/agent/tools/task_tool.py +18 -5
- {langroid-0.56.2.dist-info → langroid-0.56.4.dist-info}/METADATA +1 -1
- {langroid-0.56.2.dist-info → langroid-0.56.4.dist-info}/RECORD +6 -6
- {langroid-0.56.2.dist-info → langroid-0.56.4.dist-info}/WHEEL +0 -0
- {langroid-0.56.2.dist-info → langroid-0.56.4.dist-info}/licenses/LICENSE +0 -0
langroid/agent/base.py
CHANGED
@@ -265,8 +265,10 @@ class Agent(ABC):
|
|
265
265
|
"""
|
266
266
|
sig = inspect.signature(handler_method)
|
267
267
|
params = list(sig.parameters.values())
|
268
|
-
# Remove 'self' parameter
|
269
|
-
params = [
|
268
|
+
# Remove the first 'self' parameter
|
269
|
+
params = params[1:]
|
270
|
+
# Don't use name
|
271
|
+
# [p for p in params if p.name != "self"]
|
270
272
|
|
271
273
|
agent_param = None
|
272
274
|
chat_doc_param = None
|
@@ -277,18 +279,30 @@ class Agent(ABC):
|
|
277
279
|
if param.annotation != inspect.Parameter.empty:
|
278
280
|
ann_str = str(param.annotation)
|
279
281
|
# Check for Agent-like types
|
282
|
+
print(param, inspect.isclass(param.annotation))
|
283
|
+
print(param, issubclass(param.annotation, Agent))
|
284
|
+
print(param, param.annotation is ChatDocument)
|
280
285
|
if (
|
281
|
-
param.annotation
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
+
inspect.isclass(param.annotation)
|
287
|
+
and issubclass(param.annotation, Agent)
|
288
|
+
) or (
|
289
|
+
not inspect.isclass(param.annotation)
|
290
|
+
and (
|
291
|
+
"Agent" in ann_str
|
292
|
+
or (
|
293
|
+
hasattr(param.annotation, "__name__")
|
294
|
+
and "Agent" in param.annotation.__name__
|
295
|
+
)
|
286
296
|
)
|
287
297
|
):
|
288
298
|
agent_param = param.name
|
289
299
|
has_annotations = True
|
290
300
|
# Check for ChatDocument-like types
|
291
|
-
elif
|
301
|
+
elif (
|
302
|
+
param.annotation is ChatDocument
|
303
|
+
or "ChatDocument" in ann_str
|
304
|
+
or "ChatDoc" in ann_str
|
305
|
+
):
|
292
306
|
chat_doc_param = param.name
|
293
307
|
has_annotations = True
|
294
308
|
|
@@ -298,12 +312,12 @@ class Agent(ABC):
|
|
298
312
|
elif param.name == "chat_doc":
|
299
313
|
chat_doc_param = param.name
|
300
314
|
|
315
|
+
print(has_annotations, agent_param, chat_doc_param)
|
301
316
|
return has_annotations, agent_param, chat_doc_param
|
302
317
|
|
303
318
|
@no_type_check
|
304
319
|
def _create_handler_wrapper(
|
305
320
|
self,
|
306
|
-
message_class: Type[ToolMessage],
|
307
321
|
handler_method: Any,
|
308
322
|
is_async: bool = False,
|
309
323
|
) -> Any:
|
@@ -320,7 +334,8 @@ class Agent(ABC):
|
|
320
334
|
"""
|
321
335
|
sig = inspect.signature(handler_method)
|
322
336
|
params = list(sig.parameters.values())
|
323
|
-
params = [
|
337
|
+
params = params[1:]
|
338
|
+
# params = [p for p in params if p.name != "self"]
|
324
339
|
|
325
340
|
has_annotations, agent_param, chat_doc_param = self._analyze_handler_params(
|
326
341
|
handler_method,
|
@@ -471,7 +486,6 @@ class Agent(ABC):
|
|
471
486
|
See `tests/main/test_stateless_tool_messages.py` for an example.
|
472
487
|
"""
|
473
488
|
wrapper = self._create_handler_wrapper(
|
474
|
-
message_class,
|
475
489
|
message_class.handle,
|
476
490
|
is_async=False,
|
477
491
|
)
|
@@ -521,7 +535,6 @@ class Agent(ABC):
|
|
521
535
|
and not hasattr(self, async_handler_name)
|
522
536
|
):
|
523
537
|
wrapper = self._create_handler_wrapper(
|
524
|
-
message_class,
|
525
538
|
message_class.handle_async,
|
526
539
|
is_async=True,
|
527
540
|
)
|
@@ -3,6 +3,7 @@ TaskTool: A tool that allows agents to delegate a task to a sub-agent with
|
|
3
3
|
specific tools enabled.
|
4
4
|
"""
|
5
5
|
|
6
|
+
import uuid
|
6
7
|
from typing import List, Optional
|
7
8
|
|
8
9
|
import langroid.language_models as lm
|
@@ -17,6 +18,10 @@ from langroid.pydantic_v1 import Field
|
|
17
18
|
class TaskTool(ToolMessage):
|
18
19
|
"""
|
19
20
|
Tool that spawns a sub-agent with specified tools to handle a task.
|
21
|
+
|
22
|
+
The sub-agent can be given a custom name for identification in logs.
|
23
|
+
If no name is provided, a random unique name starting with 'agent'
|
24
|
+
will be generated.
|
20
25
|
"""
|
21
26
|
|
22
27
|
request: str = "task_tool"
|
@@ -24,11 +29,7 @@ class TaskTool(ToolMessage):
|
|
24
29
|
<HowToUse>
|
25
30
|
Use this tool to delegate a task to a sub-agent with specific tools enabled.
|
26
31
|
The sub-agent will be created with the specified tools and will run the task
|
27
|
-
non-interactively.
|
28
|
-
|
29
|
-
- `system_message`:
|
30
|
-
|
31
|
-
|
32
|
+
non-interactively.
|
32
33
|
"""
|
33
34
|
|
34
35
|
# Parameters for the agent tool
|
@@ -87,6 +88,14 @@ class TaskTool(ToolMessage):
|
|
87
88
|
default=None,
|
88
89
|
description="Optional max iterations for the sub-agent to run the task",
|
89
90
|
)
|
91
|
+
agent_name: Optional[str] = Field(
|
92
|
+
default=None,
|
93
|
+
description="""
|
94
|
+
Optional name for the sub-agent. This will be used as the agent's name
|
95
|
+
in logs and for identification purposes. If not provided, a random unique
|
96
|
+
name starting with 'agent' will be generated.
|
97
|
+
""",
|
98
|
+
)
|
90
99
|
|
91
100
|
def _set_up_task(self, agent: ChatAgent) -> Task:
|
92
101
|
"""
|
@@ -95,6 +104,9 @@ class TaskTool(ToolMessage):
|
|
95
104
|
Args:
|
96
105
|
agent: The parent ChatAgent that is handling this tool
|
97
106
|
"""
|
107
|
+
# Generate a random name if not provided
|
108
|
+
agent_name = self.agent_name or f"agent-{str(uuid.uuid4())[:8]}"
|
109
|
+
|
98
110
|
# Create chat agent config with system message if provided
|
99
111
|
# TODO: Maybe we just copy the parent agent's config and override chat_model?
|
100
112
|
# -- but what if parent agent has a MockLMConfig?
|
@@ -102,6 +114,7 @@ class TaskTool(ToolMessage):
|
|
102
114
|
chat_model=self.model or "gpt-4.1-mini", # Default model if not specified
|
103
115
|
)
|
104
116
|
config = ChatAgentConfig(
|
117
|
+
name=agent_name,
|
105
118
|
llm=llm_config,
|
106
119
|
system_message=f"""
|
107
120
|
{self.system_message}
|
@@ -3,7 +3,7 @@ langroid/exceptions.py,sha256=OPjece_8cwg94DLPcOGA1ddzy5bGh65pxzcHMnssTz8,2995
|
|
3
3
|
langroid/mytypes.py,sha256=HIcYAqGeA9OK0Hlscym2FI5Oax9QFljDZoVgRlomhRk,4014
|
4
4
|
langroid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
langroid/agent/__init__.py,sha256=ll0Cubd2DZ-fsCMl7e10hf9ZjFGKzphfBco396IKITY,786
|
6
|
-
langroid/agent/base.py,sha256=
|
6
|
+
langroid/agent/base.py,sha256=EMZGPVSqd4_optr9_FG1TLRF8-noEAloen8J4c7Ayto,86262
|
7
7
|
langroid/agent/batch.py,sha256=wpE9RqCNDVDhAXkCB7wEqfCIEAi6qKcrhaZ-Zr9T4C0,21375
|
8
8
|
langroid/agent/chat_agent.py,sha256=2HIYzYxkrGkRIS97ioKfIqjaW3RbX89M39LjzBobBEY,88381
|
9
9
|
langroid/agent/chat_document.py,sha256=0e6zYkqIorMIVbCsxOul9ziwAPPOWDsBsRV9E8ux-WI,18055
|
@@ -54,7 +54,7 @@ langroid/agent/tools/recipient_tool.py,sha256=dr0yTxgNEIoxUYxH6TtaExC4G_8WdJ0xGo
|
|
54
54
|
langroid/agent/tools/retrieval_tool.py,sha256=zcAV20PP_6VzSd-UE-IJcabaBseFL_QNz59Bnig8-lE,946
|
55
55
|
langroid/agent/tools/rewind_tool.py,sha256=XAXL3BpNhCmBGYq_qi_sZfHJuIw7NY2jp4wnojJ7WRs,5606
|
56
56
|
langroid/agent/tools/segment_extract_tool.py,sha256=__srZ_VGYLVOdPrITUM8S0HpmX4q7r5FHWMDdHdEv8w,1440
|
57
|
-
langroid/agent/tools/task_tool.py,sha256=
|
57
|
+
langroid/agent/tools/task_tool.py,sha256=VOHWv8uFPRczf6qp8YZPpUirkCqE6YVhN6jgXCvdpe0,7102
|
58
58
|
langroid/agent/tools/tavily_search_tool.py,sha256=soI-j0HdgVQLf09wRQScaEK4b5RpAX9C4cwOivRFWWI,1903
|
59
59
|
langroid/agent/tools/mcp/__init__.py,sha256=DJNM0VeFnFS3pJKCyFGggT8JVjVu0rBzrGzasT1HaSM,387
|
60
60
|
langroid/agent/tools/mcp/decorators.py,sha256=h7dterhsmvWJ8q4mp_OopmuG2DF71ty8cZwOyzdDZuk,1127
|
@@ -137,7 +137,7 @@ langroid/vector_store/pineconedb.py,sha256=otxXZNaBKb9f_H75HTaU3lMHiaR2NUp5MqwLZ
|
|
137
137
|
langroid/vector_store/postgres.py,sha256=wHPtIi2qM4fhO4pMQr95pz1ZCe7dTb2hxl4VYspGZoA,16104
|
138
138
|
langroid/vector_store/qdrantdb.py,sha256=O6dSBoDZ0jzfeVBd7LLvsXu083xs2fxXtPa9gGX3JX4,18443
|
139
139
|
langroid/vector_store/weaviatedb.py,sha256=Yn8pg139gOy3zkaPfoTbMXEEBCiLiYa1MU5d_3UA1K4,11847
|
140
|
-
langroid-0.56.
|
141
|
-
langroid-0.56.
|
142
|
-
langroid-0.56.
|
143
|
-
langroid-0.56.
|
140
|
+
langroid-0.56.4.dist-info/METADATA,sha256=punxDL35bHKw4J-PDHEMYfWvwb7gu3ccpuMlTPmU1GU,65744
|
141
|
+
langroid-0.56.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
142
|
+
langroid-0.56.4.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
143
|
+
langroid-0.56.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|