Skip to content

Commit ac69a92

Browse files
committed
add phi data agent example
1 parent 4bee1c4 commit ac69a92

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

examples/agents/phidata.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from phi.agent import Agent
2+
from phi.model.openai import OpenAIChat
3+
from phi.tools.duckduckgo import DuckDuckGo
4+
from observers.observers import wrap_openai
5+
from observers.stores import DatasetsStore
6+
from openai import OpenAI
7+
8+
9+
client = wrap_openai(OpenAI(), store=DatasetsStore(repo_name="websearch-agent-traces"))
10+
11+
web_agent = Agent(
12+
name="Web Agent",
13+
model=OpenAIChat(id="gpt-4o", client=client),
14+
tools=[DuckDuckGo()],
15+
instructions=["Always include sources"],
16+
show_tool_calls=True,
17+
markdown=True,
18+
)
19+
web_agent.print_response("Whats happening in France?")

src/observers/base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,34 @@
22
from abc import ABC, abstractmethod
33
from dataclasses import dataclass, field
44
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional
5+
from typing_extensions import Literal
56

67
if TYPE_CHECKING:
78
from argilla import Argilla
89

910

11+
@dataclass
12+
class Function:
13+
"""Function tool call information"""
14+
15+
name: str
16+
arguments: str
17+
18+
19+
@dataclass
20+
class ToolCall:
21+
"""Tool call information"""
22+
23+
id: str
24+
type: Literal["function"]
25+
function: Function
26+
27+
1028
@dataclass
1129
class Message:
1230
role: Literal["system", "user", "assistant", "function"]
1331
content: str
32+
tool_calls: Optional[List[ToolCall]] = None
1433

1534

1635
@dataclass

src/observers/stores/migrations/001_create_schema_version.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS openai_records (
99
id VARCHAR PRIMARY KEY,
1010
model VARCHAR,
1111
timestamp TIMESTAMP,
12-
messages STRUCT(role VARCHAR, content VARCHAR)[],
12+
messages JSON,
1313
assistant_message TEXT,
1414
completion_tokens INTEGER,
1515
prompt_tokens INTEGER,

0 commit comments

Comments
 (0)