Skip to content

Commit 6edea6a

Browse files
enhance workflow code for Python (#412)
* enhance workflow shared code * fix streaming * refactor code * add missing helper * update * update form filling * add filters * simplify the code * simplify the code * simplify the code * update form filling * update e2e * update function calling agent * fix unneeded condition * Create light-parrots-work.md * revert change on using functioncallingagent * update readme * clean code * extract call one tool function * update for blog use case * fix streaming * fix e2e * fix missing await * improve tools code * improve assertion code * skip form filling test for TS framework * update for tools helper --------- Co-authored-by: Marcus Schiesser <[email protected]>
1 parent d79d165 commit 6edea6a

File tree

25 files changed

+969
-813
lines changed

25 files changed

+969
-813
lines changed

.changeset/light-parrots-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Optimize generated workflow code for Python

e2e/shared/multiagent_template.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ const templateUI: TemplateUI = "shadcn";
1818
const templatePostInstallAction: TemplatePostInstallAction = "runApp";
1919
const appType: AppType = templateFramework === "nextjs" ? "" : "--frontend";
2020
const userMessage = "Write a blog post about physical standards for letters";
21-
const templateAgents = ["financial_report", "blog"];
21+
const templateAgents = ["financial_report", "blog", "form_filling"];
2222

2323
for (const agents of templateAgents) {
2424
test.describe(`Test multiagent template ${agents} ${templateFramework} ${dataSource} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
2525
test.skip(
2626
process.platform !== "linux" || process.env.DATASOURCE === "--no-files",
2727
"The multiagent template currently only works with files. We also only run on Linux to speed up tests.",
2828
);
29+
test.skip(
30+
agents === "form_filling" && templateFramework !== "fastapi",
31+
"Form filling is currently only supported with FastAPI.",
32+
);
2933
let port: number;
3034
let externalPort: number;
3135
let cwd: string;
@@ -68,6 +72,10 @@ for (const agents of templateAgents) {
6872
test("Frontend should be able to submit a message and receive the start of a streamed response", async ({
6973
page,
7074
}) => {
75+
test.skip(
76+
agents === "financial_report" || agents === "form_filling",
77+
"Skip chat tests for financial report and form filling.",
78+
);
7179
await page.goto(`http://localhost:${port}`);
7280
await page.fill("form textarea", userMessage);
7381

templates/components/agents/python/blog/README-template.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ This example is using three agents to generate a blog post:
88

99
There are three different methods how the agents can interact to reach their goal:
1010

11-
1. [Choreography](./app/examples/choreography.py) - the agents decide themselves to delegate a task to another agent
12-
1. [Orchestrator](./app/examples/orchestrator.py) - a central orchestrator decides which agent should execute a task
13-
1. [Explicit Workflow](./app/examples/workflow.py) - a pre-defined workflow specific for the task is used to execute the tasks
11+
1. [Choreography](./app/agents/choreography.py) - the agents decide themselves to delegate a task to another agent
12+
1. [Orchestrator](./app/agents/orchestrator.py) - a central orchestrator decides which agent should execute a task
13+
1. [Explicit Workflow](./app/agents/workflow.py) - a pre-defined workflow specific for the task is used to execute the tasks
1414

1515
## Getting Started
1616

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .blog import create_workflow
2+
3+
__all__ = ["create_workflow"]

templates/components/agents/python/blog/app/engine/engine.py renamed to templates/components/agents/python/blog/app/workflows/blog.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44

55
from app.agents.choreography import create_choreography
66
from app.agents.orchestrator import create_orchestrator
7-
from app.agents.workflow import create_workflow
7+
from app.agents.workflow import create_workflow as create_blog_workflow
88
from llama_index.core.chat_engine.types import ChatMessage
99
from llama_index.core.workflow import Workflow
1010

1111
logger = logging.getLogger("uvicorn")
1212

1313

14-
def get_chat_engine(
14+
def create_workflow(
1515
chat_history: Optional[List[ChatMessage]] = None, **kwargs
1616
) -> Workflow:
17-
# TODO: the EXAMPLE_TYPE could be passed as a chat config parameter?
17+
# Chat filters are not supported yet
18+
kwargs.pop("filters", None)
1819
agent_type = os.getenv("EXAMPLE_TYPE", "").lower()
1920
match agent_type:
2021
case "choreography":
2122
agent = create_choreography(chat_history, **kwargs)
2223
case "orchestrator":
2324
agent = create_orchestrator(chat_history, **kwargs)
2425
case _:
25-
agent = create_workflow(chat_history, **kwargs)
26+
agent = create_blog_workflow(chat_history, **kwargs)
2627

2728
logger.info(f"Using agent pattern: {agent_type}")
2829

templates/components/multiagent/python/app/workflows/single.py renamed to templates/components/agents/python/blog/app/workflows/single.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def to_response(self) -> dict:
4242
return {
4343
"type": "agent",
4444
"data": {
45-
"name": self.name,
45+
"agent": self.name,
4646
"type": self.event_type.value,
47-
"msg": self.msg,
47+
"text": self.msg,
4848
"data": self.data,
4949
},
5050
}

templates/components/agents/python/financial_report/README-template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ curl --location 'localhost:8000/api/chat' \
3333
--data '{ "messages": [{ "role": "user", "content": "Create a report comparing the finances of Apple and Tesla" }] }'
3434
```
3535

36-
You can start editing the API by modifying `app/api/routers/chat.py` or `app/financial_report/workflow.py`. The API auto-updates as you save the files.
36+
You can start editing the API by modifying `app/api/routers/chat.py` or `app/workflows/financial_report.py`. The API auto-updates as you save the files.
3737

3838
Open [http://localhost:8000/docs](http://localhost:8000/docs) with your browser to see the Swagger UI of the API.
3939

templates/components/agents/python/financial_report/app/agents/analyst.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

templates/components/agents/python/financial_report/app/agents/reporter.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

templates/components/agents/python/financial_report/app/agents/researcher.py

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)