Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate AgentRunner to Agent Workflow (Python) #502

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b4f0767
stg
leehuwuj Feb 11, 2025
bc2d503
raise error if there is no tools
leehuwuj Feb 11, 2025
cbebd03
stg
leehuwuj Feb 12, 2025
5ec1947
support request api
leehuwuj Feb 12, 2025
6d5749d
remove --no-files e2e test for python
leehuwuj Feb 12, 2025
22e4be9
use agent workflow for financial report use case
leehuwuj Feb 12, 2025
6ba5023
migrate form_filling to AgentWorkflow
leehuwuj Feb 13, 2025
0e4ee4a
refactor: chat message content
thucpn Feb 13, 2025
86610e6
rename function in chat-ui
thucpn Feb 14, 2025
8d3db71
Create cool-cars-promise.md
marcusschiesser Feb 17, 2025
5a230be
bump chat-ui
leehuwuj Feb 18, 2025
7e23d77
add new query index and weather card for agent workflows
leehuwuj Feb 18, 2025
0139a11
support source nodes
leehuwuj Feb 18, 2025
dae3249
remove unused function
leehuwuj Feb 18, 2025
798f378
fix empty chunk
leehuwuj Feb 19, 2025
d09ae65
keep the old code for financial report and form-filling
leehuwuj Feb 19, 2025
c7e4696
fix annotation message
leehuwuj Feb 19, 2025
c83fa96
fix mypy
leehuwuj Feb 19, 2025
25144dc
add artifact tool component
leehuwuj Feb 24, 2025
fe5982e
fix render empty div
leehuwuj Feb 24, 2025
1e90a6a
improve typing
leehuwuj Feb 24, 2025
087a45e
Merge remote-tracking branch 'origin' into lee/agent-workflows
leehuwuj Feb 25, 2025
d38eb3c
unify chat.py file
leehuwuj Feb 25, 2025
9fd6d0c
remove multiagent folder (python)
leehuwuj Feb 25, 2025
d0f606d
fix linting
leehuwuj Feb 25, 2025
21b7df1
fix missing import
leehuwuj Feb 25, 2025
c996508
support non-streaming api
leehuwuj Feb 25, 2025
be5870c
update citation prompt
leehuwuj Feb 25, 2025
8004c9f
remove dead code
leehuwuj Feb 25, 2025
b60618a
remove dead code
leehuwuj Feb 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-cars-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Migrate AgentRunner to Agent Workflow (Python)
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: ["3.11"]
os: [macos-latest, windows-latest, ubuntu-22.04]
frameworks: ["fastapi"]
datasources: ["--no-files", "--example-file", "--llamacloud"]
datasources: ["--example-file", "--llamacloud"]
defaults:
run:
shell: bash
Expand Down
19 changes: 9 additions & 10 deletions helpers/env-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,12 @@ const getSystemPromptEnv = (
});
}
if (tools?.length == 0 && (dataSources?.length ?? 0 > 0)) {
const citationPrompt = `'You have provided information from a knowledge base that has been passed to you in nodes of information.
Each node has useful metadata such as node ID, file name, page, etc.
Please add the citation to the data node for each sentence or paragraph that you reference in the provided information.
The citation format is: . [citation:<node_id>]()
Where the <node_id> is the unique identifier of the data node.
const citationPrompt = `'You have provided information from a knowledge base that separates the information into multiple nodes.
Always add a citation to each sentence or paragraph that you reference in the provided information using the node_id field in the header of each node.

The citation format is: [citation:<node_id>]
Where the <node_id> is the node_id field in the header of each node.
Always separate the citation by a space.

Example:
We have two nodes:
Expand All @@ -497,11 +498,9 @@ We have two nodes:
node_id: abc
file_name: animal.pdf

User question: Tell me a fun fact about Llama.
Your answer:
A baby llama is called "Cria" [citation:xyz]().
It often live in desert [citation:abc]().
It\\'s cute animal.
Your answer with citations:
A baby llama is called "Cria" [citation:xyz]
It often lives in desert [citation:abc] [citation:xyz]
'`;
systemPromptEnv.push({
name: "SYSTEM_CITATION_PROMPT",
Expand Down
13 changes: 0 additions & 13 deletions helpers/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,23 +470,10 @@ export const installPythonTemplate = async ({
}
}

// Copy engine code
await copy("**", enginePath, {
parents: true,
cwd: path.join(compPath, "engines", "python", engine),
});

// Copy router code
await copyRouterCode(root, tools ?? []);
}

// Copy multiagents overrides
if (template === "multiagent") {
await copy("**", path.join(root), {
cwd: path.join(compPath, "multiagent", "python"),
});
}

if (template === "multiagent" || template === "reflex") {
if (useCase) {
const sourcePath =
Expand Down
10 changes: 6 additions & 4 deletions questions/datasources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export const getDataSourceChoices = (
});
}
if (selectedDataSource === undefined || selectedDataSource.length === 0) {
choices.push({
title: "No datasource",
value: "none",
});
if (framework !== "fastapi") {
choices.push({
title: "No datasource",
value: "none",
});
}
choices.push({
title:
process.platform !== "linux"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

from app.engine.index import IndexConfig, get_index
from app.workflows.agents import plan_research, research, write_report
from app.workflows.events import SourceNodesEvent
from app.workflows.models import (
CollectAnswersEvent,
DataEvent,
PlanResearchEvent,
ReportEvent,
ResearchEvent,
SourceNodesEvent,
)

logger = logging.getLogger("uvicorn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from llama_index.core.workflow import Event
from pydantic import BaseModel

from app.api.routers.models import SourceNodes


# Workflow events
class PlanResearchEvent(Event):
Expand Down Expand Up @@ -41,3 +43,18 @@ class DataEvent(Event):

def to_response(self):
return self.model_dump()


class SourceNodesEvent(Event):
nodes: List[NodeWithScore]

def to_response(self):
return {
"type": "sources",
"data": {
"nodes": [
SourceNodes.from_source_node(node).model_dump()
for node in self.nodes
]
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from enum import Enum
from typing import List, Optional

from llama_index.core.schema import NodeWithScore
from llama_index.core.workflow import Event

from app.api.routers.models import SourceNodes


class AgentRunEventType(Enum):
TEXT = "text"
PROGRESS = "progress"


class AgentRunEvent(Event):
name: str
msg: str
event_type: AgentRunEventType = AgentRunEventType.TEXT
data: Optional[dict] = None

def to_response(self) -> dict:
return {
"type": "agent",
"data": {
"agent": self.name,
"type": self.event_type.value,
"text": self.msg,
"data": self.data,
},
}


class SourceNodesEvent(Event):
nodes: List[NodeWithScore]

def to_response(self):
return {
"type": "sources",
"data": {
"nodes": [
SourceNodes.from_source_node(node).model_dump()
for node in self.nodes
]
},
}
Loading