Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions packages/uipath-llamaindex/samples/chat-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Literature Chat Agent

An AI assistant using Llamaindex and Tavily search for literature research and recommendations.

## Requirements

- Python 3.11+
- OpenAI API key
- Tavily API key

## Installation

```bash
uv venv -p 3.11 .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv sync
```

Set your API keys as environment variables in .env

```bash
OPENAI_API_KEY=your_anthropic_api_key
TAVILY_API_KEY=your_tavily_api_key
```

## Usage

```bash
uipath run agent 'uipath run agent '{"user_msg": "Tell me about 1984 by George Orwell"}''
```
19 changes: 19 additions & 0 deletions packages/uipath-llamaindex/samples/chat-agent/agent.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
flowchart TB
__start__(__start__)
aggregate_tool_results(aggregate_tool_results)
call_tool(call_tool)
init_run(init_run)
parse_agent_output(parse_agent_output)
run_agent_step(run_agent_step)
setup_agent(setup_agent)
__end__(__end__)
aggregate_tool_results --> |AgentInput|setup_agent
aggregate_tool_results --> |StopEvent|__end__
call_tool --> |ToolCallResult|aggregate_tool_results
__start__ --> |AgentWorkflowStartEvent|init_run
init_run --> |AgentInput|setup_agent
parse_agent_output --> |StopEvent|__end__
parse_agent_output --> |AgentInput|setup_agent
parse_agent_output --> |ToolCall|call_tool
run_agent_step --> |AgentOutput|parse_agent_output
setup_agent --> |AgentSetup|run_agent_step
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workflows": {
"agent": "main.py:agent"
}
}
35 changes: 35 additions & 0 deletions packages/uipath-llamaindex/samples/chat-agent/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os

from llama_index.core.agent.workflow import FunctionAgent, AgentWorkflow
from llama_index.llms.openai import OpenAI
from llama_index.tools.tavily_research import TavilyToolSpec

llm = OpenAI(model="gpt-4o-mini")
tavily_tool = TavilyToolSpec(api_key=os.environ["TAVILY_API_KEY"])

SYSTEM_PROMPT = (
"You are an advanced AI assistant specializing in book research and literature analysis. "
"Your primary functions are:\n\n"
"1. Book Information Research: Gather comprehensive information about books, including plot summaries, "
"themes, publishing details, sales performance, critical reception, and awards.\n"
"2. Author Research: Provide detailed information about authors, translators, editors, and other "
"publishing industry professionals.\n"
"3. Book Recommendations: Suggest books based on user preferences, genres, themes, or similar books "
"they have enjoyed.\n"
"4. Publishing Industry Analysis: Analyze trends, bestseller data, genre popularity, and insights "
"from the literary world.\n"
"5. Book Trivia and Facts: Share interesting facts, behind-the-scenes stories, and trivia about "
"books, authors, and the publishing industry.\n\n"
"Use the search tool for recent or factual information. "
"Remember previous messages and maintain context across the discussion."
)

agent = AgentWorkflow.from_tools_or_functions(
tools_or_functions=tavily_tool.to_tool_list(),
llm=llm,
system_prompt=SYSTEM_PROMPT
)

async def chat(user_input: str) -> str:
response = await agent.run(user_msg=user_input)
return str(response)
18 changes: 18 additions & 0 deletions packages/uipath-llamaindex/samples/chat-agent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "chat-agent"
version = "0.0.1"
description = "chat-agent"
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
dependencies = [
"uipath-llamaindex>=0.5.0, <0.6.0",
"llama-index-llms-openai>=0.6.10",
"llama-index-tools-tavily-research>=0.4.2",
"llama-index-llms-openai>=0.6.18"
]
requires-python = ">=3.11"


[dependency-groups]
dev = [
"uipath-dev>=0.0.19",
]
14 changes: 14 additions & 0 deletions packages/uipath-llamaindex/samples/chat-agent/uipath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://cloud.uipath.com/draft/2024-12/uipath",
"runtimeOptions": {
"isConversational": true
},
"packOptions": {
"fileExtensionsIncluded": [],
"filesIncluded": [],
"filesExcluded": [],
"directoriesExcluded": [],
"includeUvLock": true
},
"functions": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from uipath_llamaindex.runtime.chat.messages import UiPathChatMessagesMapper

__all__ = ["UiPathChatMessagesMapper"]
Loading
Loading