Compare commits
No commits in common. "bb20a8474119d23e7619a82770c1e320d8946eb0" and "cbba3360492d8479f5974887eddce3efdf6f4abc" have entirely different histories.
bb20a84741
...
cbba336049
1 changed files with 7 additions and 16 deletions
|
|
@ -2,33 +2,24 @@ import asyncio
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from lambda_agent_api.agent_api import AgentApi
|
from lambda_agent_api.agent_api import AgentApi
|
||||||
from lambda_agent_api.server import MsgEventTextChunk, MsgEventToolCallChunk, MsgEventToolResult
|
from lambda_agent_api.server import MsgEventTextChunk
|
||||||
|
|
||||||
|
|
||||||
|
def my_callback(message):
|
||||||
|
print(f"Callback: {message}")
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
api = AgentApi("agent-1", "ws://localhost:8000/agent_ws/")
|
api = AgentApi("agent-1", "ws://localhost:8000/agent_ws/", callback=my_callback)
|
||||||
|
|
||||||
await api.connect()
|
await api.connect()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
prompt = await asyncio.get_event_loop().run_in_executor(None, input, ">>> ")
|
prompt = await asyncio.get_event_loop().run_in_executor(None, input, ">>> ")
|
||||||
print("Agent: ", end="")
|
print("Agent: ", end="")
|
||||||
is_tool = False
|
|
||||||
async for chunk in api.send_message(prompt):
|
async for chunk in api.send_message(prompt):
|
||||||
match chunk:
|
if isinstance(chunk, MsgEventTextChunk):
|
||||||
case MsgEventTextChunk():
|
|
||||||
is_tool = False
|
|
||||||
print(chunk.text, end="", flush=True)
|
print(chunk.text, end="", flush=True)
|
||||||
case MsgEventToolCallChunk():
|
|
||||||
if not is_tool:
|
|
||||||
print(f"\n\n### TOOL CALL: ({chunk.tool_name}) ", end="", flush=True)
|
|
||||||
is_tool = True
|
|
||||||
print(chunk.args_chunk, end="", flush=True)
|
|
||||||
case MsgEventToolResult():
|
|
||||||
is_tool = False
|
|
||||||
print(f"\nResult: {chunk.result}\n\n", end="", flush=True)
|
|
||||||
|
|
||||||
print("\n")
|
print("\n")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue