You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am following the quickstart and running the code myself.
The first agent writes a reply to the email successfully.
The second agent intended to mark emails as spam fails reliably (see #399).
The third example that uses two agents fails reliably.
It classifies and responds to the first and third emails, however the second email fails with an sqlite database exception.
The output follows:
╭─ Agent: Email Classifier ────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_2c595d48_successful" │
│ │
│ Tool args: {'task_result': 0} │
│ │
│ Tool result: Task #2c595d48 ("Classify this email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:21:04 AM ─╯
╭─ Agent: Email Responder ─────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_e32d6968_successful" │
│ │
│ Tool args: {'task_result': 'Hello,\n\nThank you for reaching out. The project is │
│ progressing well and we are on track with our timeline. We will provide a detailed update │
│ by the end of the week. If you have any specific questions or need further information in │
│ the meantime, please feel free to let me know.\n\nBest regards,\n\n[Your Name]'} │
│ │
│ Tool result: Task #e32d6968 ("Write a response to this important email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:21:06 AM ─╯
Hello,
Thank you for reaching out. The project is progressing well and we are on track with our timeline. We will provide a detailed update by the end of the week. If you have any specific questions or need further information in the meantime, please feel free to let me know.
Best regards,
[Your Name]
╭─ Agent: Email Classifier ────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_a7b742ab_successful" │
│ │
│ Tool args: {'task_result': 1} │
│ │
│ Tool result: Task #a7b742ab ("Classify this email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:21:08 AM ─╯
No response needed for spam email.
None
11:21:08.296 | ERROR | uvicorn.error - Exception in ASGI application
Traceback (most recent call last):
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1964](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=1963), in _exec_single_context
self.dialect.do_execute(
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 942](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/default.py#line=941), in do_execute
cursor.execute(statement, parameters)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 150](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py#line=149), in execute
self._adapt_connection._handle_exception(error)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 301](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py#line=300), in _handle_exception
raise error
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 132](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py#line=131), in execute
self.await_(_cursor.execute(operation, parameters))
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 132](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py#line=131), in await_only
return current.parent.switch(awaitable) # type: ignore[no-any-return,attr-defined] # noqa: E501
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 196](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py#line=195), in greenlet_spawn
value = await result
^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py", line 48](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py#line=47), in execute
await self._execute(self._cursor.execute, sql, parameters)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py", line 40](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py#line=39), in _execute
return await self._conn._execute(fn, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py", line 132](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py#line=131), in _execute
return await future
^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py", line 115](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py#line=114), in run
result = function()
^^^^^^^^^^
sqlite3.OperationalError: database is locked
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 403](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py#line=402), in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py#line=59), in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1054](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/applications.py#line=1053), in __call__
await super().__call__(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/applications.py", line 113](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/applications.py#line=112), in __call__
await self.middleware_stack(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py#line=186), in __call__
raise exc
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py#line=164), in __call__
await self.app(scope, receive, _send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/api/server.py", line 157](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/api/server.py#line=156), in __call__
await self.app(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/cors.py#line=84), in __call__
await self.app(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py#line=61), in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py#line=52), in wrapped_app
raise exc
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py#line=41), in wrapped_app
await app(scope, receive, sender)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 715](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=714), in __call__
await self.middleware_stack(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 735](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=734), in app
await route.handle(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 460](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=459), in handle
await self.app(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1054](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/applications.py#line=1053), in __call__
await super().__call__(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/applications.py", line 113](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/applications.py#line=112), in __call__
await self.middleware_stack(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py#line=186), in __call__
raise exc
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py#line=164), in __call__
await self.app(scope, receive, _send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 20](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/gzip.py#line=19), in __call__
await responder(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 39](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/gzip.py#line=38), in __call__
await self.app(scope, receive, self.send_with_gzip)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py#line=61), in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py#line=52), in wrapped_app
raise exc
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py#line=41), in wrapped_app
await app(scope, receive, sender)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 715](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=714), in __call__
await self.middleware_stack(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 735](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=734), in app
await route.handle(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 288](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=287), in handle
await self.app(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 76](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=75), in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py#line=52), in wrapped_app
raise exc
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py#line=41), in wrapped_app
await app(scope, receive, sender)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 73](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/starlette/routing.py#line=72), in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/utilities/server.py", line 50](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/utilities/server.py#line=49), in handle_response_scoped_depends
response = await default_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/routing.py", line 301](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/routing.py#line=300), in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/routing.py", line 212](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/fastapi/routing.py#line=211), in run_endpoint_function
return await dependant.call(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/api/flow_runs.py", line 92](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/api/flow_runs.py#line=91), in create_flow_run
model = await models.flow_runs.create_flow_run(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/models/flow_runs.py", line 104](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/prefect/server/models/flow_runs.py#line=103), in create_flow_run
await session.flush()
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/ext/asyncio/session.py", line 802](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/ext/asyncio/session.py#line=801), in flush
await greenlet_spawn(self.sync_session.flush, objects=objects)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 203](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py#line=202), in greenlet_spawn
result = context.switch(value)
^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4353](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/session.py#line=4352), in flush
self._flush(objects)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4488](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/session.py#line=4487), in _flush
with util.safe_reraise():
^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py#line=145), in __exit__
raise exc_value.with_traceback(exc_tb)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4449](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/session.py#line=4448), in _flush
flush_context.execute()
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py#line=465), in execute
rec.execute(self)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py#line=641), in execute
util.preloaded.orm_persistence.save_obj(
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 93](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py#line=92), in save_obj
_emit_insert_statements(
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1233](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py#line=1232), in _emit_insert_statements
result = connection.execute(
^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1416](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=1415), in execute
return meth(
^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 515](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/sql/elements.py#line=514), in _execute_on_connection
return connection._execute_clauseelement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1638](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=1637), in _execute_clauseelement
ret = self._execute_context(
^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1843](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=1842), in _execute_context
return self._exec_single_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1983](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=1982), in _exec_single_context
self._handle_dbapi_exception(
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2352](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=2351), in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1964](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/base.py#line=1963), in _exec_single_context
self.dialect.do_execute(
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 942](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/engine/default.py#line=941), in do_execute
cursor.execute(statement, parameters)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 150](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py#line=149), in execute
self._adapt_connection._handle_exception(error)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 301](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py#line=300), in _handle_exception
raise error
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 132](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py#line=131), in execute
self.await_(_cursor.execute(operation, parameters))
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 132](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py#line=131), in await_only
return current.parent.switch(awaitable) # type: ignore[no-any-return,attr-defined] # noqa: E501
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 196](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py#line=195), in greenlet_spawn
value = await result
^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py", line 48](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py#line=47), in execute
await self._execute(self._cursor.execute, sql, parameters)
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py", line 40](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/cursor.py#line=39), in _execute
return await self._conn._execute(fn, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py", line 132](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py#line=131), in _execute
return await future
^^^^^^^^^^^^
File "[/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py", line 115](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/aiosqlite/core.py#line=114), in run
result = function()
^^^^^^^^^^
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked
[SQL: INSERT INTO flow_run (flow_id, deployment_id, work_queue_name, flow_version, deployment_version, parameters, idempotency_key, context, empirical_policy, tags, labels, created_by, infrastructure_pid, job_variables, infrastructure_document_id, parent_task_run_id, auto_scheduled, state_id, work_queue_id, name, state_type, state_name, state_timestamp, run_count, expected_start_time, next_scheduled_start_time, start_time, end_time, total_run_time, id, created, updated) VALUES (:flow_id, :deployment_id, :work_queue_name, :flow_version, :deployment_version, :parameters, :idempotency_key, :context, :empirical_policy, :tags, :labels, :created_by, :infrastructure_pid, :job_variables, :infrastructure_document_id, :parent_task_run_id, :auto_scheduled, :state_id, :work_queue_id, :name, :state_type, :state_name, :state_timestamp, :run_count, :expected_start_time, :next_scheduled_start_time, :start_time, :end_time, :total_run_time, :id, :created, :updated)]
[parameters: {'flow_id': '76120b0c-fe80-4a56-aa8f-9e13a7f4b5ad', 'deployment_id': None, 'work_queue_name': None, 'flow_version': '30a2c8579f1f9857fa8524be4208e378', 'deployment_version': None, 'parameters': '{"email_content": "Urgent: Project deadline moved up by one week."}', 'idempotency_key': None, 'context': '{}', 'empirical_policy': '{"max_retries": 0, "retry_delay_seconds": 0.0, "retries": 0, "retry_delay": 0, "pause_keys": [], "resuming": false, "retry_type": null}', 'tags': '[]', 'labels': '{"prefect.flow.id": "76120b0c-fe80-4a56-aa8f-9e13a7f4b5ad"}', 'created_by': None, 'infrastructure_pid': None, 'job_variables': '{}', 'infrastructure_document_id': None, 'parent_task_run_id': None, 'auto_scheduled': 0, 'state_id': None, 'work_queue_id': None, 'name': 'steel-parakeet', 'state_type': None, 'state_name': None, 'state_timestamp': None, 'run_count': 0, 'expected_start_time': None, 'next_scheduled_start_time': None, 'start_time': None, 'end_time': None, 'total_run_time': '1970-01-01 00:00:00.000000', 'id': 'a0d72ee4-6fb2-48fe-a4a7-02a40c699ab4', 'created': '2025-01-20 11:21:08.287453', 'updated': '2025-01-20 11:21:08.290952'}]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
╭─ Agent: Email Classifier ────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_8f322520_successful" │
│ │
│ Tool args: {'task_result': 0} │
│ │
│ Tool result: Task #8f322520 ("Classify this email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:21:11 AM ─╯
╭─ Agent: Email Responder ─────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_e39f3ead_successful" │
│ │
│ Tool args: {'task_result': "Subject: Re: Urgent: Project Deadline Update\n\nHi [Recipient's │
│ Name],\n\nThank you for letting me know about the change in the project deadline. I │
│ understand the urgency and will prioritize the tasks accordingly to meet the new │
│ timeline.\n\nPlease let me know if there are any specific areas you need me to focus on or │
│ any additional resources required.\n\nBest regards,\n\n[Your Name]"} │
│ │
│ Tool result: Task #e39f3ead ("Write a response to this important email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:21:18 AM ─╯
Subject: Re: Urgent: Project Deadline Update
Hi [Recipient's Name],
Thank you for letting me know about the change in the project deadline. I understand the urgency and will prioritize the tasks accordingly to meet the new timeline.
Please let me know if there are any specific areas you need me to focus on or any additional resources required.
Best regards,
[Your Name]
Example Code
importcontrolflowascf# Create agentsclassifier=cf.Agent(
name="Email Classifier",
model="openai/gpt-4o-mini",
instructions="You are an expert at quickly classifying emails. Always ""respond with exactly one word: either 'important' or 'spam'."
)
responder=cf.Agent(
name="Email Responder",
model="openai/gpt-4o",
instructions="You are an expert at crafting professional email responses. ""Your replies should be concise but friendly."
)
# Create the flow@cf.flowdefprocess_email(email_content: str):
# Classify the emailcategory=cf.run(
f"Classify this email",
result_type=["important", "spam"],
agents=[classifier],
context=dict(email=email_content),
)
# If the email is important, write a responseifcategory=="important":
response=cf.run(
f"Write a response to this important email",
result_type=str,
agents=[responder],
context=dict(email=email_content),
)
returnresponse# Otherwise, no response is neededelse:
print("No response needed for spam email.")
emails= [
"Hello, I need an update on the project status.",
"Subject: Exclusive offer just for you!",
"Urgent: Project deadline moved up by one week.",
]
# Run the flow on each emailforemailinemails:
response=process_email(email)
print(response)
I believe that the underlying cause for this is that the process_email method returns None for spam emails.
If I replace the line print("No response needed for spam email.") with return "No response needed for spam email." then the flow completes successfully.
Updated code follows:
importcontrolflowascf# Create agentsclassifier=cf.Agent(
name="Email Classifier",
model="openai/gpt-4o-mini",
instructions="You are an expert at quickly classifying emails. Always ""respond with exactly one word: either 'important' or 'spam'."
)
responder=cf.Agent(
name="Email Responder",
model="openai/gpt-4o",
instructions="You are an expert at crafting professional email responses. ""Your replies should be concise but friendly."
)
# Create the flow@cf.flowdefprocess_email(email_content: str):
# Classify the emailcategory=cf.run(
f"Classify this email",
result_type=["important", "spam"],
agents=[classifier],
context=dict(email=email_content),
)
# If the email is important, write a responseifcategory=="important":
response=cf.run(
f"Write a response to this important email",
result_type=str,
agents=[responder],
context=dict(email=email_content),
)
returnresponse# Otherwise, no response is neededelse:
return"No response needed for spam email."emails= [
"Hello, I need an update on the project status.",
"Subject: Exclusive offer just for you!",
"Urgent: Project deadline moved up by one week.",
]
# Run the flow on each emailforemailinemails:
response=process_email(email)
print(response)
This produces the response:
╭─ Agent: Email Classifier ────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_d94765ad_successful" │
│ │
│ Tool args: {'task_result': 0} │
│ │
│ Tool result: Task #d94765ad ("Classify this email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:26:03 AM ─╯
╭─ Agent: Email Responder ─────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_c0c2d330_successful" │
│ │
│ Tool args: {'task_result': 'Hello,\n\nThank you for reaching out. The project is │
│ progressing well, and we are on track with our timeline. I will provide a detailed update │
│ by the end of the week. If you have any specific questions or need further information, │
│ please feel free to ask.\n\nBest regards,\n\n[Your Name]'} │
│ │
│ Tool result: Task #c0c2d330 ("Write a response to this important email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:26:05 AM ─╯
Hello,
Thank you for reaching out. The project is progressing well, and we are on track with our timeline. I will provide a detailed update by the end of the week. If you have any specific questions or need further information, please feel free to ask.
Best regards,
[Your Name]
╭─ Agent: Email Classifier ────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_9692524b_successful" │
│ │
│ Tool args: {'task_result': 1} │
│ │
│ Tool result: Task #9692524b ("Classify this email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:26:06 AM ─╯
No response needed for spam email.
╭─ Agent: Email Classifier ────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_2e8fa9a5_successful" │
│ │
│ Tool args: {'task_result': 0} │
│ │
│ Tool result: Task #2e8fa9a5 ("Classify this email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:26:08 AM ─╯
╭─ Agent: Email Responder ─────────────────────────────────────────────────────────────────────────╮
│ │
│ ✅ Tool call: "mark_task_2f1f0713_successful" │
│ │
│ Tool args: {'task_result': "Subject: Re: Urgent: Project Deadline Moved Up by One │
│ Week\n\nHi [Recipient's Name],\n\nThank you for the update regarding the project deadline. │
│ I appreciate the heads-up and will make the necessary adjustments to ensure we meet the new │
│ timeline.\n\nPlease let me know if there's anything specific you need from me during this │
│ period.\n\nBest regards,\n\n[Your Name]"} │
│ │
│ Tool result: Task #2f1f0713 ("Write a response to this important email") marked successful. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────── 11:26:11 AM ─╯
Subject: Re: Urgent: Project Deadline Moved Up by One Week
Hi [Recipient's Name],
Thank you for the update regarding the project deadline. I appreciate the heads-up and will make the necessary adjustments to ensure we meet the new timeline.
Please let me know if there's anything specific you need from me during this period.
Best regards,
[Your Name]
The text was updated successfully, but these errors were encountered:
Description
I am following the quickstart and running the code myself.
The first agent writes a reply to the email successfully.
The second agent intended to mark emails as spam fails reliably (see #399).
The third example that uses two agents fails reliably.
It classifies and responds to the first and third emails, however the second email fails with an sqlite database exception.
The output follows:
Example Code
Version Information
Additional Context
I believe that the underlying cause for this is that the
process_email
method returnsNone
for spam emails.If I replace the line
print("No response needed for spam email.")
withreturn "No response needed for spam email."
then the flow completes successfully.Updated code follows:
This produces the response:
The text was updated successfully, but these errors were encountered: