run-llama / llama-agents

MIT License
1.08k stars 80 forks source link

Need to add execution delay in test client #97

Closed peteryxu closed 2 days ago

peteryxu commented 6 days ago

Following the docker sample readme.md, (https://github.com/peteryxu/llama-agents/tree/learn/examples/docker-kubernetes, ) running the Client test code, and got error below.

Traceback (most recent call last): File "..../llama-agents/zPX/examples/TESTclient.py", line 5, in task_result = client.get_task_result(task_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/pxu/CODE/GenAI4Code/llama-agents/.venv/lib/python3.12/site-packages/llama_agents/client/sync_client.py", line 135, in get_task_result return TaskResult(task.state["result"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: llama_agents.types.TaskResult() argument after must be a mapping, not NoneType

Original Code ` from llama_agents import LlamaAgentsClient

client = LlamaAgentsClient("http://0.0.0.0:8001") task_id = client.create_task("What is the secret fact?") task_result = client.get_task_result(task_id) print(task_result.result) `

Simple fix: to add execution delay: ` import time

task_id = client.create_task("What is the secret fact?") time.sleep(10) task_result = client.get_task_result(task_id) `

nerdai commented 5 days ago

That sounds good. Do you want to open a PR for it?

styk-tv commented 5 days ago

please do not introduce static delays, that is absolutely silly. ideally this would be called async from client.

However, in documentation it says task_result should come back None if task_id is not ready. this is a bug @logan-markewich as correctly stated by @peteryxu since TaskResult is not accepting (**None) as parameter.

image

logan-markewich commented 5 days ago

Thats what the try/except is for -- it raises an error saying that the result isn't ready. The code sample should probably either use a sleep or a try-except.

(Originally I had it returning None, but thought raising an error is a bit more informative)

logan-markewich commented 5 days ago

@peteryxu was suggesting adding a delay for people who just copy-pasted the code example, not in the actual source code

peteryxu commented 5 days ago

@logan-markewich is right. This suggestion is just to make the docs work out of box, and developer first time experience MATTERs for adoption! We could point out this is NOT supposed for production code use.

peteryxu commented 5 days ago

That sounds good. Do you want to open a PR for it?

I will do tomorrow after the holiday -:)

peteryxu commented 2 days ago

closed as fixed in PR#106