mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 20:13:04 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import logging
|
|
from typing import Dict, Generator, Optional
|
|
|
|
from docsgpt.agents.base import BaseAgent
|
|
from docsgpt.agents.tools.internal_search import add_internal_search_tool
|
|
from docsgpt.agents.tools.wiki import add_wiki_tool
|
|
from docsgpt.logging import LogContext
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class AgenticAgent(BaseAgent):
|
|
"""Agent where the LLM controls retrieval via tools.
|
|
|
|
Unlike ClassicAgent which pre-fetches docs into the prompt,
|
|
AgenticAgent gives the LLM an internal_search tool so it can
|
|
decide when, what, and whether to search.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
retriever_config: Optional[Dict] = None,
|
|
wiki_config: Optional[Dict] = None,
|
|
*args,
|
|
**kwargs,
|
|
):
|
|
super().__init__(*args, **kwargs)
|
|
self.retriever_config = retriever_config or {}
|
|
self.wiki_config = wiki_config or {}
|
|
|
|
def _gen_inner(
|
|
self, query: str, log_context: LogContext
|
|
) -> Generator[Dict, None, None]:
|
|
tools_dict = self.tool_executor.get_tools()
|
|
add_internal_search_tool(tools_dict, self.retriever_config)
|
|
if self.wiki_config:
|
|
add_wiki_tool(tools_dict, self.wiki_config)
|
|
self._prepare_tools(tools_dict)
|
|
|
|
# 4. Build messages (prompt has NO pre-fetched docs)
|
|
messages = self._build_messages(self.prompt, query)
|
|
|
|
# 5. Call LLM — the handler manages the tool loop
|
|
llm_response = self._llm_gen(messages, log_context)
|
|
|
|
yield from self._handle_response(
|
|
llm_response, tools_dict, messages, log_context
|
|
)
|
|
|
|
# 6. Collect sources from internal search tool results
|
|
self._collect_internal_sources()
|
|
|
|
yield {"sources": self.retrieved_docs}
|
|
yield {"tool_calls": self._get_truncated_tool_calls()}
|
|
|
|
log_context.stacks.append(
|
|
{"component": "agent", "data": {"tool_calls": self.tool_calls.copy()}}
|
|
)
|