Skip to content

Commit ad99ab5

Browse files
modified: langchain-crash-course/5_agents_tools/agent_tools_basic.py
modified: pyproject.toml modified: uv.lock
2 parents 435ada8 + 10bff8a commit ad99ab5

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

langchain-crash-course/5_agents_tools/agent_tools_basic.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# agent_tools_basic.py
22
"""
33
Agent Tools Basic Application
4+
(Asynchronous Version)
45
56
This module demonstrates a basic implementation of a LangChain agent with tools.
67
It creates a ReAct (Reason and Action) agent that can use predefined tools to
@@ -21,13 +22,17 @@
2122
"""
2223

2324
# Import standard libraries
25+
import asyncio
2426
import os
2527
import sys
2628
from datetime import datetime
2729
from logging import Logger
2830
from pathlib import Path
2931
from typing import Any
3032

33+
# For async input
34+
from aioconsole import ainput
35+
3136
# Import necessary libraries
3237
from dotenv import load_dotenv
3338

@@ -84,7 +89,7 @@ def get_current_time(*args: Any, **kwargs: Any) -> str:
8489
# Set tools list to Agent
8590
tools: list = [
8691
Tool(
87-
name="Current Time",
92+
name="Time",
8893
func=get_current_time,
8994
description="Useful to know the current time.",
9095
),
@@ -130,7 +135,7 @@ def get_current_time(*args: Any, **kwargs: Any) -> str:
130135

131136

132137
# Run agent executor
133-
def main() -> None:
138+
async def main() -> None:
134139
"""
135140
Main function to run the agent executor.
136141
@@ -144,7 +149,7 @@ def main() -> None:
144149
while True:
145150
try:
146151
# User Query
147-
query: str = input("You: ").strip()
152+
query: str = (await ainput("You: ")).strip()
148153

149154
if not query:
150155
continue
@@ -155,7 +160,7 @@ def main() -> None:
155160
break
156161

157162
# Run agent executor
158-
response: Any = agent_executor.invoke(input={"input": query})
163+
response: Any = await agent_executor.ainvoke(input={"input": query})
159164
logger.info(msg="Agent response generated successfully")
160165
print(f"Agent: {response['output']}")
161166

@@ -170,4 +175,4 @@ def main() -> None:
170175

171176
# Main entry point
172177
if __name__ == "__main__":
173-
main()
178+
asyncio.run(main())

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ dependencies = [
2020
"nltk>=3.9.1",
2121
"langchain-huggingface>=0.3.1",
2222
"beautifulsoup4>=4.13.5",
23-
23+
"aioconsole>=0.8.1",
24+
"wikipedia>=1.4.0",
2425
]
2526

2627
[dependency-groups]

uv.lock

Lines changed: 23 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)