langroid 0.19.5__py3-none-any.whl → 0.20.1__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 +29 -14
- langroid/agent/special/arangodb/arangodb_agent.py +649 -0
- langroid/agent/special/arangodb/system_messages.py +183 -0
- langroid/agent/special/arangodb/tools.py +102 -0
- langroid/agent/special/arangodb/utils.py +36 -0
- langroid/agent/special/neo4j/neo4j_chat_agent.py +120 -54
- langroid/agent/special/neo4j/system_messages.py +120 -0
- langroid/agent/special/neo4j/tools.py +32 -0
- langroid/agent/special/sql/sql_chat_agent.py +8 -3
- langroid/agent/task.py +78 -56
- langroid/agent/tools/orchestration.py +7 -7
- langroid/parsing/parser.py +6 -0
- {langroid-0.19.5.dist-info → langroid-0.20.1.dist-info}/METADATA +5 -1
- {langroid-0.19.5.dist-info → langroid-0.20.1.dist-info}/RECORD +18 -13
- pyproject.toml +7 -1
- langroid/agent/special/neo4j/utils/system_message.py +0 -64
- /langroid/agent/special/{neo4j/utils → arangodb}/__init__.py +0 -0
- {langroid-0.19.5.dist-info → langroid-0.20.1.dist-info}/LICENSE +0 -0
- {langroid-0.19.5.dist-info → langroid-0.20.1.dist-info}/WHEEL +0 -0
langroid/agent/base.py
CHANGED
@@ -94,6 +94,9 @@ class AgentConfig(BaseSettings):
|
|
94
94
|
respond_tools_only: bool = False # respond only to tool messages (not plain text)?
|
95
95
|
# allow multiple tool messages in a single response?
|
96
96
|
allow_multiple_tools: bool = True
|
97
|
+
human_prompt: str = (
|
98
|
+
"Human (respond or q, x to exit current level, " "or hit enter to continue)"
|
99
|
+
)
|
97
100
|
|
98
101
|
@validator("name")
|
99
102
|
def check_name_alphanum(cls, v: str) -> str:
|
@@ -411,16 +414,13 @@ class Agent(ABC):
|
|
411
414
|
results = self.handle_message(msg)
|
412
415
|
if results is None:
|
413
416
|
return None
|
414
|
-
if isinstance(results, ChatDocument):
|
415
|
-
# Preserve trail of tool_ids for OpenAI Assistant fn-calls
|
416
|
-
results.metadata.tool_ids = (
|
417
|
-
[] if isinstance(msg, str) else msg.metadata.tool_ids
|
418
|
-
)
|
419
|
-
return results
|
420
417
|
if not settings.quiet:
|
421
|
-
|
422
|
-
|
423
|
-
)
|
418
|
+
if isinstance(results, str):
|
419
|
+
results_str = results
|
420
|
+
elif isinstance(results, ChatDocument):
|
421
|
+
results_str = results.content
|
422
|
+
elif isinstance(results, dict):
|
423
|
+
results_str = json.dumps(results, indent=2)
|
424
424
|
console.print(f"[red]{self.indent}", end="")
|
425
425
|
print(f"[red]Agent: {escape(results_str)}")
|
426
426
|
maybe_json = len(extract_top_level_json(results_str)) > 0
|
@@ -428,6 +428,12 @@ class Agent(ABC):
|
|
428
428
|
content=results_str,
|
429
429
|
language="json" if maybe_json else "text",
|
430
430
|
)
|
431
|
+
if isinstance(results, ChatDocument):
|
432
|
+
# Preserve trail of tool_ids for OpenAI Assistant fn-calls
|
433
|
+
results.metadata.tool_ids = (
|
434
|
+
[] if isinstance(msg, str) else msg.metadata.tool_ids
|
435
|
+
)
|
436
|
+
return results
|
431
437
|
sender_name = self.config.name
|
432
438
|
if isinstance(msg, ChatDocument) and msg.function_call is not None:
|
433
439
|
# if result was from handling an LLM `function_call`,
|
@@ -655,9 +661,9 @@ class Agent(ABC):
|
|
655
661
|
user_msg = self.callbacks.get_user_response(prompt="")
|
656
662
|
else:
|
657
663
|
user_msg = Prompt.ask(
|
658
|
-
f"[blue]{self.indent}
|
659
|
-
|
660
|
-
f"
|
664
|
+
f"[blue]{self.indent}"
|
665
|
+
+ self.config.human_prompt
|
666
|
+
+ f"\n{self.indent}"
|
661
667
|
).strip()
|
662
668
|
|
663
669
|
tool_ids = []
|
@@ -668,7 +674,7 @@ class Agent(ABC):
|
|
668
674
|
return None
|
669
675
|
else:
|
670
676
|
if user_msg.startswith("SYSTEM"):
|
671
|
-
user_msg = user_msg
|
677
|
+
user_msg = user_msg.replace("SYSTEM", "").strip()
|
672
678
|
source = Entity.SYSTEM
|
673
679
|
sender = Entity.SYSTEM
|
674
680
|
else:
|
@@ -874,7 +880,13 @@ class Agent(ABC):
|
|
874
880
|
return cdoc
|
875
881
|
|
876
882
|
def has_tool_message_attempt(self, msg: str | ChatDocument | None) -> bool:
|
877
|
-
"""
|
883
|
+
"""
|
884
|
+
Check whether msg contains a Tool/fn-call attempt (by the LLM).
|
885
|
+
|
886
|
+
CAUTION: This uses self.get_tool_messages(msg) which as a side-effect
|
887
|
+
may update msg.tool_messages when msg is a ChatDocument, if there are
|
888
|
+
any tools in msg.
|
889
|
+
"""
|
878
890
|
if msg is None:
|
879
891
|
return False
|
880
892
|
try:
|
@@ -915,6 +927,9 @@ class Agent(ABC):
|
|
915
927
|
) -> List[ToolMessage]:
|
916
928
|
"""
|
917
929
|
Get ToolMessages recognized in msg, handle-able by this agent.
|
930
|
+
NOTE: as a side-effect, this will update msg.tool_messages
|
931
|
+
when msg is a ChatDocument and msg contains tool messages.
|
932
|
+
|
918
933
|
If all_tools is True:
|
919
934
|
- return all tools, i.e. any tool in self.llm_tools_known,
|
920
935
|
whether it is handled by this agent or not;
|