superagent-ai / superagent

🥷 Run AI-agents with an API
https://docs.superagent.sh
MIT License
5.35k stars 846 forks source link

Workflows raise an exception #703

Closed 7flash closed 10 months ago

7flash commented 10 months ago

Description

Error

Traceback (most recent call last):
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/superagent/resources/workflow/client.py", line 191, in invoke
    _response_json = _response.json()
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/httpx/_models.py", line 762, in json
    return jsonlib.loads(self.content, **kwargs)
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 44, in <module>
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/superagent/resources/workflow/client.py", line 193, in invoke
    raise ApiError(status_code=_response.status_code, body=_response.text)
superagent.core.api_error.ApiError: status_code: 500, body: Internal Server Error

Steps to reproduce

to reproduce, execute this script

python3 -c '''
import os
from superagent.client import Superagent

client = Superagent(
    base_url="https://api.beta.superagent.sh",
    token=os.environ["SUPERAGENT_API_KEY"]
)

agent1 = client.agent.create(request={
    "name": "jan28-agent-first",
    "description": "An Assistant that can create blog post contents",
    "avatar": "https://example.com/logo.png", # Replace with a real image
    "isActive": True,
    "llmModel": "GPT_3_5_TURBO_16K_0613",
    "initialMessage": "Hi there, how can I help you?",
    "prompt": "Create blog post contents."
})

agent2 = client.agent.create(request={
    "name": "jan28-agent-second",
    "description": "An Assistant that can generate image",
    "avatar": "https://example.com/logo2.png", # Replace with a real image
    "isActive": True,
    "llmModel": "GPT_3_5_TURBO_16K_0613",
    "initialMessage": "Hi there, how can I help you?",
    "prompt": "Use the SDXL API to generate an image."
})

workflow = client.workflow.create(request={
    "name": "jan28-workflow-first",
    "description": "Useful for generating blog post",
})

step1 = client.workflow.add_step(workflow_id=workflow.data.id, request={
    "agentId": agent1.data.id,
    "order": 0
})
step2 = client.workflow.add_step(workflow_id=workflow.data.id, request={
    "agentId": agent2.data.id,
    "order": 1
})

response = client.workflow.invoke(workflow_id=workflow.data.id, input="create a blog post about AI", enable_streaming=False)

print(response)

'''
Traceback (most recent call last):
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/superagent/resources/workflow/client.py", line 191, in invoke
    _response_json = _response.json()
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/httpx/_models.py", line 762, in json
    return jsonlib.loads(self.content, **kwargs)
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 44, in <module>
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/superagent/resources/workflow/client.py", line 193, in invoke
    raise ApiError(status_code=_response.status_code, body=_response.text)
superagent.core.api_error.ApiError: status_code: 500, body: Internal Server Error
ppython3 -c '''
from superagent.client import Superagent

client = Superagent(token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfdXNlcl9pZCI6Ijg1YTBiZTQ3LTM4ZjgtNDI4Ny05YmE0LTY0NWRlYzE2NjQ4NCJ9.Z3b046pXUz6dxDG66XsslSSHTpWzEKUTO4H22F5uCJY", base_url="https://api.beta.superagent.sh")

agent = client.agent.create(request={
    "name": "My Agent",
    "description": "My awesome agent",
    "isActive": True,
    "llmModel": "GPT_4_1106_PREVIEW",
    "prompt": "You are a helpful assistant"
})

output = client.agent.invoke(
    agent_id=agent.data.id,
    input="Hi there!",
    enable_streaming=False,
    session_id="123"
)

print("Received response from superagent", agent.data)
'''
Received response from superagent id='eab8f799-74e1-4064-9a6c-eac3b8862b7f' name='My Agent' avatar=None initial_message=None description='My awesome agent' is_active=True created_at=datetime.datetime(2024, 1, 28, 7, 27, 42, 857000, tzinfo=datetime.timezone.utc) updated_at=datetime.datetime(2024, 1, 28, 7, 27, 42, 857000, tzinfo=datetime.timezone.utc) llms=[] llm_model=<LlmModel.GPT_4_1106_PREVIEW: 'GPT_4_1106_PREVIEW'> prompt='You are a helpful assistant' api_user_id='85a0be47-38f8-4287-9ba4-645dec166484' api_user=None datasources=[] tools=[] workflow_steps=None
ppython3 -c '''
import os
from superagent.client import Superagent

client = Superagent(
    base_url="https://api.beta.superagent.sh",
    token=os.environ["SUPERAGENT_API_KEY"]
)

agent1 = client.agent.create(request={
    "name": "jan28-agent-first",
    "description": "An Assistant that can create blog post contents",
    "avatar": "https://example.com/logo.png", # Replace with a real image
    "isActive": True,
    "llmModel": "GPT_3_5_TURBO_16K_0613",
    "initialMessage": "Hi there, how can I help you?",
    "prompt": "Create blog post contents."
})

agent2 = client.agent.create(request={
    "name": "jan28-agent-second",
    "description": "An Assistant that can generate image",
    "avatar": "https://example.com/logo2.png", # Replace with a real image
    "isActive": True,
    "llmModel": "GPT_3_5_TURBO_16K_0613",
    "initialMessage": "Hi there, how can I help you?",
    "prompt": "Use the SDXL API to generate an image."
})

workflow = client.workflow.create(request={
    "name": "jan28-workflow-first",
    "description": "Useful for generating blog post",
})

step1 = client.workflow.add_step(workflow_id=workflow.data.id, request={
    "agentId": agent1.data.id,
    "order": 0
})
step2 = client.workflow.add_step(workflow_id=workflow.data.id, request={
    "agentId": agent2.data.id,
    "order": 1
})

response = client.workflow.invoke(workflow_id=workflow.data.id, input="create a blog post about AI", enable_streaming=False)

print(response)

'''

Acknowledgements

homanp commented 10 months ago

Thanks for reporting! @elisalimli could you have a look?

7flash commented 10 months ago

Thanks for reporting! @elisalimli could you have a look?

Still not working

Traceback (most recent call last):
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/site-packages/httpcore/_backends/sync.py", line 126, in read
    return self._sock.recv(max_bytes)
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/ssl.py", line 1292, in recv
    return self.read(buflen)
  File "/Users/gur/miniconda3/envs/superagent/lib/python3.10/ssl.py", line 1165, in read
    return self._sslobj.read(len)
TimeoutError: The read operation timed out
elisalimli commented 10 months ago

@homanp needs to release a new version I guess. @7flash after you update Superagent Python SDK to the latest version this should work.

homanp commented 10 months ago

@7flash I'm updating the sdks now.

homanp commented 10 months ago

@elisalimli @7flash we have some upstream issues with the service we are using to generate the sdk definition, I'm working with them to resolve this. Get back to you ASAP!

homanp commented 10 months ago

@7flash we just released a new version of our SDK that should fix this issue. Please circle back if you are experiencing issues

7flash commented 10 months ago

@7flash we just released a new version of our SDK that should fix this issue. Please circle back if you are experiencing issues

Still not working

httpx.ReadTimeout: The read operation timed out


pip3 show superagent-py Name: superagent-py Version: 0.1.68