11# agent_tools_basic.py
22"""
33Agent Tools Basic Application
4+ (Asynchronous Version)
45
56This module demonstrates a basic implementation of a LangChain agent with tools.
67It creates a ReAct (Reason and Action) agent that can use predefined tools to
2122"""
2223
2324# Import standard libraries
25+ import asyncio
2426import os
2527import sys
2628from datetime import datetime
2729from logging import Logger
2830from pathlib import Path
2931from typing import Any
3032
33+ # For async input
34+ from aioconsole import ainput
35+
3136# Import necessary libraries
3237from dotenv import load_dotenv
3338
@@ -84,7 +89,7 @@ def get_current_time(*args: Any, **kwargs: Any) -> str:
8489# Set tools list to Agent
8590tools : 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
172177if __name__ == "__main__" :
173- main ()
178+ asyncio . run ( main () )
0 commit comments