2111964d8b
Подключает stub-инструменты и последовательный Agno workflow в CLI и AgentOS, чтобы запускать сценарий по URL и получать структурированный JSON-результат.
97 lines
2.6 KiB
Python
97 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
from typing import Any
|
|
|
|
|
|
def _utc_now_iso() -> str:
|
|
return datetime.now(timezone.utc).isoformat()
|
|
|
|
|
|
def _base_result(tool_name: str, ok: bool, payload: dict[str, Any]) -> dict[str, Any]:
|
|
return {
|
|
"tool_name": tool_name,
|
|
"ok": ok,
|
|
"payload": payload,
|
|
"received_at": _utc_now_iso(),
|
|
}
|
|
|
|
|
|
async def stub_search_news_sources(url: str) -> dict[str, Any]:
|
|
return _base_result(
|
|
tool_name="search_news_sources",
|
|
ok=True,
|
|
payload={
|
|
"input_url": url,
|
|
"items": [
|
|
{"url": "https://news-a.example/article-1"},
|
|
{"url": "https://news-b.example/article-2"},
|
|
{"url": "https://news-c.example/article-3"},
|
|
],
|
|
},
|
|
)
|
|
|
|
|
|
async def stub_parse_article(url: str) -> dict[str, Any]:
|
|
return _base_result(
|
|
tool_name="parse_article",
|
|
ok=True,
|
|
payload={
|
|
"url": url,
|
|
"title": "Stub article title",
|
|
"published_at": "2026-01-01T10:00:00+00:00",
|
|
"text": "Stub parsed article content.",
|
|
},
|
|
)
|
|
|
|
|
|
async def stub_extract_publication_date(article_text: str) -> dict[str, Any]:
|
|
return _base_result(
|
|
tool_name="extract_publication_date",
|
|
ok=True,
|
|
payload={
|
|
"text_size": len(article_text),
|
|
"published_at": "2026-01-01T10:00:00+00:00",
|
|
"confidence": 0.77,
|
|
},
|
|
)
|
|
|
|
|
|
async def stub_rank_sources_by_date(items: list[dict[str, Any]]) -> dict[str, Any]:
|
|
ranked = sorted(items, key=lambda item: str(item.get("published_at", "")))
|
|
return _base_result(
|
|
tool_name="rank_sources_by_date",
|
|
ok=True,
|
|
payload={
|
|
"input_count": len(items),
|
|
"ranked_items": ranked,
|
|
},
|
|
)
|
|
|
|
|
|
async def stub_generate_summary(items: list[dict[str, Any]]) -> dict[str, Any]:
|
|
first_url = ""
|
|
if items:
|
|
first_url = str(items[0].get("url", ""))
|
|
|
|
return _base_result(
|
|
tool_name="generate_summary",
|
|
ok=True,
|
|
payload={
|
|
"input_count": len(items),
|
|
"summary": (
|
|
"По заглушечным данным самым ранним источником считается "
|
|
+ first_url
|
|
),
|
|
},
|
|
)
|
|
|
|
|
|
STUB_TOOLS: dict[str, Any] = {
|
|
"search_news_sources": stub_search_news_sources,
|
|
"parse_article": stub_parse_article,
|
|
"extract_publication_date": stub_extract_publication_date,
|
|
"rank_sources_by_date": stub_rank_sources_by_date,
|
|
"generate_summary": stub_generate_summary,
|
|
}
|