mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 10:13:06 +00:00
Rewrite the default/creative/strict presets (classic + agentic) into
structured sections: grounding and cite-by-title guidance, insufficient-
context behavior, current date, respond-in-user-language, scoped mermaid
usage, an untrusted-content guardrail, and a conditional XML-tagged
document context block. A memory directory listing is injected at render
time via the template prefetch mechanism so the model starts oriented
without burning a tool call.
Fixes along the way:
- Agentic preset swap was dead code: _get_prompt_content cached the
classic preset before create_agent's swap check ran, so agentic and
research agents always got the classic preset. The swap now happens
inside _get_prompt_content.
- Jinja autoescape corrupted document content in custom prompts
(< -> <); prompts are not HTML, autoescape is now off.
- Literal {summaries} leaked into the prompt when no docs were
retrieved; the placeholder is now stripped.
- Agentic/research prompts referenced tool names from a dropped naming
scheme (search_internal, reason_think); they now reference the real
names (search, reason).
- The strict preset told the model to "be very creative and use your
imagination" right after "never make up information".
- extract_tool_usages recorded intermediate attribute chains as
bare-tool usages, which meant "run all actions" at prefetch; only
maximal chains are recorded now.
- Headless runs retrieved docs but never rendered them into the
prompt; the prompt is now rendered like the streaming path.
- Default tools were unreachable by name in prompt templates
(prefetch results were keyed by synthetic id only); defaults now
claim the name key unless an explicit row shadows it.
Tool layer: memory/notes/todo actions are namespaced (memory_view,
note_overwrite, todo_create, ...) with legacy unprefixed names still
accepted via prefix stripping; duplicate action names across tools are
disambiguated with the owning tool's name instead of numeric suffixes;
thin tool descriptions rewritten (brave, duckduckgo, telegram, ntfy,
cryptoprice, read_webpage, internal_search, think).
Docs are now wrapped per chunk in <document index>/<source>/<content>
tags for citation-by-title support.
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
import requests
|
|
from application.agents.tools.base import Tool
|
|
|
|
|
|
class CryptoPriceTool(Tool):
|
|
"""
|
|
CryptoPrice
|
|
A tool for retrieving cryptocurrency prices using the CryptoCompare public API
|
|
"""
|
|
|
|
def __init__(self, config):
|
|
self.config = config
|
|
|
|
def execute_action(self, action_name, **kwargs):
|
|
actions = {"cryptoprice_get": self._get_price}
|
|
|
|
if action_name in actions:
|
|
return actions[action_name](**kwargs)
|
|
else:
|
|
raise ValueError(f"Unknown action: {action_name}")
|
|
|
|
def _get_price(self, symbol, currency):
|
|
"""
|
|
Fetches the current price of a given cryptocurrency symbol in the specified currency.
|
|
Example:
|
|
symbol = "BTC"
|
|
currency = "USD"
|
|
returns price in USD.
|
|
"""
|
|
url = f"https://min-api.cryptocompare.com/data/price?fsym={symbol.upper()}&tsyms={currency.upper()}"
|
|
response = requests.get(url, timeout=100)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if currency.upper() in data:
|
|
return {
|
|
"status_code": response.status_code,
|
|
"price": data[currency.upper()],
|
|
"message": f"Price of {symbol.upper()} in {currency.upper()} retrieved successfully.",
|
|
}
|
|
else:
|
|
return {
|
|
"status_code": response.status_code,
|
|
"message": f"Couldn't find price for {symbol.upper()} in {currency.upper()}.",
|
|
}
|
|
else:
|
|
return {
|
|
"status_code": response.status_code,
|
|
"message": "Failed to retrieve price.",
|
|
}
|
|
|
|
def get_actions_metadata(self):
|
|
return [
|
|
{
|
|
"name": "cryptoprice_get",
|
|
"description": (
|
|
"Get the current price of a cryptocurrency from the public "
|
|
"CryptoCompare API. Use ticker symbols, e.g. symbol='BTC', "
|
|
"currency='USD'."
|
|
),
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"symbol": {
|
|
"type": "string",
|
|
"description": "The cryptocurrency symbol (e.g. BTC)",
|
|
},
|
|
"currency": {
|
|
"type": "string",
|
|
"description": "The currency in which you want the price (e.g. USD)",
|
|
},
|
|
},
|
|
"required": ["symbol", "currency"],
|
|
"additionalProperties": False,
|
|
},
|
|
}
|
|
]
|
|
|
|
def get_config_requirements(self):
|
|
# No specific configuration needed for this tool as it just queries a public endpoint
|
|
return {}
|