Skip to content

Commit 7605df9

Browse files
Update to v0.3.0
1 parent b980952 commit 7605df9

11 files changed

Lines changed: 1072 additions & 668 deletions

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ Available in [French](https://zanomega.com/open-taranis/fr/)
138138
- [X] v0.0.x: Add and confirm other API providers (in the cloud, not locally)
139139
- [X] v0.1.x: Functionality verifications in [examples](https://github.com/SyntaxError4Life/open-taranis/blob/main/examples/)
140140
- [X] v0.2.x: Add features for **logic-only coding** approach, start with `agent_base`
141-
- [ ] v0.3.x: Add a full agent in **TUI** and upgrade web client **deployments**
141+
- [X] v0.3.x: Add a full agent in **TUI** and upgrade web client **deployments**
142+
- [ ] v0.4.x: Improving support for **local AI deployment**
142143
- The rest will follow soon.
143144

144145
## Changelog
@@ -168,16 +169,20 @@ Available in [French](https://zanomega.com/open-taranis/fr/)
168169
- **v0.2.4** : Improved CoT techniques and updated `web_front.py`, deploy an agent to the browser in a few lines
169170
</details>
170171

172+
<details><summary><b>v0.3.x : The restart</b></summary>
173+
174+
- **v0.3.0** : **Rewrite all** the code from scratch (without AI) to **improve everything**
175+
- **v0.3.1 (future)** : Add a **built-in agent** in the **TUI** + full doc in french and english
176+
</details>
177+
171178

172179
## Advanced Examples
173180

174-
- [tools call in a JSON database](https://github.com/SyntaxError4Life/open-taranis/blob/main/examples/test_json_database.py)
175-
- [tools call in a HR JSON database in multi-rounds](https://github.com/SyntaxError4Life/open-taranis/blob/main/examples/test_HR_json_database.py)
176181
- [simple search agent with Brave API](https://github.com/SyntaxError4Life/open-taranis/blob/main/examples/brave_research.py)
177182
- [full auto search agent with Brave API](https://github.com/SyntaxError4Life/open-taranis/blob/main/examples/brave_research_loop.py)
178183
- [agent with compressible memory (recommended with Kimi)](https://github.com/SyntaxError4Life/open-taranis/blob/main/examples/infinite_agent_v1.py)
179184

180185
## Links
181186

182187
- [PyPI](https://pypi.org/project/open-taranis/)
183-
- [GitHub Repository](https://github.com/SyntaxError4Life/open-taranis)
188+
- [GitHub Repository](https://github.com/SyntaxError4Life/open-taranis)

examples/brave_research.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import open_taranis as T
22
from open_taranis.tools import brave_research, fast_scraping
33

4-
client = T.clients.openrouter(api_key=None)
5-
request = T.clients.openrouter_request
4+
MODEL = "nvidia/nemotron-3-super-120b-a12b:free"
5+
6+
client = T.Clients.openrouter
7+
request = T.Request(
8+
tools=T.functions_to_tools([brave_research,fast_scraping])
9+
)
610

711
messages = [
8-
T.create_system_prompt("""You are an expert, autonomous web research assistant. Your role is to use your web search tools to answer the user's questions with precision and thoroughness.
12+
T.create.system_prompt("""You are an expert, autonomous web research assistant. Your role is to use your web search tools to answer the user's questions with precision and thoroughness.
913
1014
## General Behavior Rules
1115
- Be objective, concise, and factual in your responses.
@@ -45,24 +49,29 @@
4549
4650
Your ultimate goal is to provide a **complete, exact, and sourced** answer using all available web navigation capabilities.
4751
"""),
48-
T.create_user_prompt(input("Request : "))
52+
T.create.user_prompt(input("Request : "))
4953
]
5054

5155
run = True
5256

5357
while run :
5458
respond=""
55-
56-
for token, tool_calls, run in T.handle_streaming(request(
57-
client=client,messages=messages,model="stepfun/step-3.5-flash:free",
58-
tools=T.functions_to_tools([brave_research,fast_scraping])
59-
)):
60-
if token :
61-
print(token, end="")
59+
reasoning=""
60+
61+
for token, is_thinking, tool_calls, run, meta in T.handle_streaming(
62+
request=request,
63+
client=client,
64+
model=MODEL,
65+
messages=messages
66+
):
67+
if is_thinking:
68+
reasoning+=token
69+
else :
70+
print(token, end="", flush=True)
6271
respond+=token
63-
72+
6473
if run :
65-
messages.append(T.create_assistant_response(respond, tool_calls))
74+
messages.append(T.create.assistant_response(respond, tool_calls))
6675

6776
for tool_call in tool_calls :
6877
fid, fname, args, _ = T.handle_tool_call(tool_call)
@@ -98,9 +107,13 @@
98107
print(f"Search error : {results}")
99108
tool_response = results
100109

101-
messages.append(T.create_function_response(
110+
messages.append(T.create.function_response(
102111
id=fid,result=tool_response,name=fname
103112
))
104113

105114
if not run :
106-
messages.append(T.create_assistant_response(respond))
115+
messages.append(T.create.assistant_response(respond))
116+
117+
print("\n\n")
118+
print("="*60)
119+
print(meta)

examples/brave_research_loop.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
MODEL = "stepfun/step-3.5-flash:free"
2-
# Recommend GLM 4.7 but not free...
1+
MODEL = "nvidia/nemotron-3-super-120b-a12b:free"
32

4-
# Coded in v0.2.1
3+
# Coded in v0.2.1 but adapted in v0.3.0 !
54

65
# ==============================================================
76

@@ -12,8 +11,12 @@ class Brave_Agent(T.agent_base):
1211
def __init__(self):
1312
super().__init__()
1413

15-
self.client = T.clients.openrouter()
16-
self._system_prompt = [T.create_system_prompt("""You are an expert, autonomous web research assistant. Your role is to use your web search tools to answer the user's questions with precision and thoroughness.
14+
self.client = T.Clients.openrouter
15+
self.request_profil = T.Request(
16+
tools=T.functions_to_tools([fast_scraping, brave_research])
17+
)
18+
19+
self._system_prompt = [T.create.system_prompt("""You are an expert, autonomous web research assistant. Your role is to use your web search tools to answer the user's questions with precision and thoroughness.
1720
1821
## General Behavior Rules
1922
- Be objective, concise, and factual in your responses.
@@ -60,12 +63,12 @@ def __init__(self):
6063
])
6164

6265

63-
def create_stream(self):
64-
return T.clients.openrouter_request(
65-
client=self.client,
66-
messages=self._system_prompt+self.messages,
66+
def create_stream(self, history):
67+
return T.handle_streaming(
68+
self.request_profil,
69+
self.client,
6770
model=MODEL,
68-
tools=self.tools,
71+
messages=self._system_prompt + history
6972
)
7073

7174
def execute_tools(self, fname, args):
@@ -101,35 +104,38 @@ def execute_tools(self, fname, args):
101104
print(f"Search error : {results}")
102105
return results
103106

104-
def manage_messages_after_reply(self):
107+
def manage_messages_after_reply(self, history):
105108

106109
# Remove the content from all tool results after the agent have finished
107110
i = 0
108-
for msg in self.messages:
109-
if msg["role"] == 'tool':
110-
self.messages[i] = T.create_function_response(
111-
id=msg["tool_call_id"],result="",name=msg["name"]
112-
)
113-
114-
i+=1
111+
history = T.remove_from.auto(
112+
history,
113+
tool_response=True
114+
)
115115

116-
self.messages = self.messages[-200:] # Remember the last 200 messages (tools and user/assistant)
116+
history = history[-200:] # Remember the last 200 messages (tools and user/assistant)
117+
118+
return history
119+
120+
def manage_token_yield(self, token, is_thinking = None, meta = None, tool_calls = None):
121+
return token, meta
117122

118123
My_agent = Brave_Agent()
119124

125+
Cost = {'prompt_tokens': 0, 'completion_tokens': 0, 'cached_tokens': 0}
120126

121127
while True :
122128
prompt = input("user : ")
123129

124130
if prompt == "/exit":
125131
print("="*60)
126-
127-
132+
print(f"Total cost : {Cost}")
128133
exit()
129134

130135
print("\n\nagent : ", end="")
131136

132-
for t in My_agent(prompt):
137+
for t, meta in My_agent(T.create.user_prompt(prompt)):
133138
print(t, end="", flush=True)
134139

140+
Cost = T.add_meta(Cost, meta)
135141
print("\n\n","="*60,"\n")

examples/infinite_agent_v1.py

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
1-
MODEL = "arcee-ai/trinity-large-preview:free"
1+
MODEL = "nvidia/nemotron-3-super-120b-a12b:free"
22

33
import open_taranis as T
44

5-
CLIENT = T.clients.openrouter()
6-
REQUEST = T.clients.openrouter_request
5+
CLIENT = T.Clients.openrouter
6+
REQUEST = T.Request()
77
MAX_TOKENS = 16000
88

99
# Made with v0.2.4
10-
if T.__version__ < "0.2.4":
11-
exit(f"Version v0.2.4 minimum required, you have v{T.__version__}")
10+
if T.__version__ < "0.3.0":
11+
exit(f"Version v0.3.0 minimum required, you have v{T.__version__}")
1212

1313
# =========================================
1414

1515
class Infinite_Agent(T.agent_base):
1616
def __init__(self):
17-
super().__init__(is_thinking_enabled = True)
17+
super().__init__()
1818

1919
self.system_prompt = """"You are a compressive memory AI agent.
2020
NEVER speak about your memory to the user (it is private to you)!
2121
Here is the current state of your memory: You must ALWAYS respond in the user's language."
2222
"""
2323
self.memory = ""
24+
self.Cost = {'prompt_tokens': 0, 'completion_tokens': 0, 'cached_tokens': 0}
2425

25-
self._system_prompt = [T.create_system_prompt(self.system_prompt)]
26+
self._system_prompt = [T.create.system_prompt(self.system_prompt)]
2627
self.turns = 1
2728

28-
def create_stream(self):
29-
return REQUEST(
30-
client=CLIENT,
31-
messages=self._system_prompt + self.messages,
32-
model=MODEL
29+
def create_stream(self, history):
30+
return T.handle_streaming(
31+
REQUEST,
32+
CLIENT,
33+
MODEL,
34+
messages=self._system_prompt + history
3335
)
3436

35-
def manage_messages_after_reply(self):
37+
def manage_messages_after_reply(self, history):
38+
meta = {'prompt_tokens': 0, 'completion_tokens': 0, 'cached_tokens': 0}
39+
new_memory = ""
3640

37-
38-
3941
if self.turns % 2 == 0 :
4042

4143
print("\n\n---\nMemory being compressed\n---\n")
42-
stream = REQUEST(CLIENT,
43-
messages=[
44-
T.create_assistant_response(f"""You are an AI information summarizer.
44+
messages=[
45+
T.create.assistant_response(f"""You are an AI information summarizer.
4546
You will receive the current memory and the current conversation; you must integrate the latter into the summary (by creating a new one).
4647
Maximize relevant information while keeping in mind that the summary must be extensible (e.g., noting missing information).
4748
In this new summary (serving as memory for the rest of the session), you must include ONLY that and nothing else in the USER language !
@@ -52,29 +53,38 @@ def manage_messages_after_reply(self):
5253
5354
5455
And the current conversation:
55-
""")] + self.messages + [
56-
T.create_system_prompt("End of conversation!!"),
57-
T.create_user_prompt("Summarize the entire memory/conversation as requested.")],
58-
model=MODEL,
59-
temperature=0.2,
60-
max_tokens=MAX_TOKENS
61-
)
56+
""")] + history + [
57+
T.create.system_prompt("End of conversation!!"),
58+
T.create.user_prompt("Summarize the entire memory/conversation as requested.")
59+
]
60+
6261

6362
is_thinking = False
6463
new_memory = ""
65-
for token, _, _ in T.handle_streaming(stream):
66-
is_thinking, norm_tok, cot_tok = T.handle_thinking(token, is_thinking)
67-
68-
if norm_tok :
69-
new_memory += norm_tok
64+
for token, is_thinking, _, _, meta, in T.handle_streaming(
65+
REQUEST, CLIENT, MODEL,
66+
messages=messages
67+
):
68+
69+
if not is_thinking :
70+
new_memory += token
71+
72+
self.memory = new_memory
7073

71-
self.memory = T.remove_thinks(new_memory)
72-
self._system_prompt = [T.create_system_prompt(
74+
self._system_prompt = [T.create.system_prompt(
7375
self.system_prompt + self.memory
7476
)]
7577

76-
self.messages = self.messages[-8:]
78+
79+
history = history[-8:]
7780
self.turns += 1
81+
self.Cost = T.add_meta(self.Cost, meta)
82+
83+
84+
return history
85+
86+
def manage_token_yield(self, token, is_thinking = None, meta = None, tool_calls = None):
87+
return token, meta
7888

7989
My_agent = Infinite_Agent()
8090

@@ -83,14 +93,18 @@ def manage_messages_after_reply(self):
8393

8494
if prompt == "/exit":
8595
print("="*60)
96+
print(f"Total cost : {My_agent.Cost}")
97+
print("="*60)
8698

8799
print(My_agent.memory)
88100

89101
exit()
90102

91103
print("\n\nagent : ", end="")
92104

93-
for t in My_agent(prompt):
105+
for t, meta in My_agent(T.create.user_prompt(prompt)):
94106
print(t, end="", flush=True)
95107

108+
My_agent.Cost = T.add_meta(My_agent.Cost, meta)
109+
96110
print("\n\n","="*60,"\n")

0 commit comments

Comments
 (0)