Files
8.-samopisnyy-poiskovyy-age…/SOLUTION.md
T
kuzakhmetovartur fea117b469
CI / build (3.1) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled
feat: solution for '8. Самописный поисковый агент на основе deep agents from scratch'
2026-07-01 13:50:40 +03:00

55 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**What was implemented**
- Added the required dependencies (`langchain-openai` and `langchain-community`) to `package.json`.
- Reimplemented the search agent using LangChains `DeepAgent` instead of the previous custom logic.
- Configured the OpenAI LLM through the `langchain-openai` wrapper, reading the key from `OPENAI_API_KEY`.
- Integrated the builtin `SearchTool` from `langchain-community` so the agent can perform web searches automatically.
- Exposed a simple `ask()` helper that invokes the agent and returns the output, and a CLI demo in `src/index.js`.
**Why the main parts satisfy the requirements**
- **LangChain usage** `DeepAgent` is instantiated directly (`src/agent.js`), meeting the “use LangChains Deep Agent API” constraint.
- **OpenAI API via langchain-openai** The LLM is created with `new OpenAI({...})` from `langchain-openai`, ensuring all calls go through that package.
- **Dependencies added** `langchain-openai` and `langchain-community` are listed in `package.json`, satisfying the dependency requirement.
- **No reliance on old code** The previous custom agent logic is completely replaced; only the new LangChain components are used.
- **Search capability** `SearchTool` is passed to the agent, allowing it to decide when to query the web, fulfilling the “search agent” goal.
**Key code excerpts**
`package.json`
```json
"dependencies": {
"langchain": "^0.0.112",
"langchain-openai": "^0.0.112",
"langchain-community": "^0.0.112"
}
```
`src/agent.js`
```js
import { DeepAgent } from "langchain/agents";
import { OpenAI } from "langchain-openai";
import { SearchTool } from "langchain-community/tools/search";
const llm = new OpenAI({ temperature: 0, modelName: "gpt-3.5-turbo" });
const searchTool = new SearchTool();
const agent = new DeepAgent({
llm,
tools: [searchTool],
verbose: true
});
```
`src/index.js` (invocation)
```js
export async function ask(query) {
const result = await agent.invoke({ input: query });
return result.output;
}
```
**Honest limitations**
- The implementation assumes `OPENAI_API_KEY` is set; no fallback or user prompt is provided.
- No custom error handling beyond the basic try/catch in the CLI demo.
- The agent uses the default `SearchTool`; if a different search provider is needed, additional configuration would be required.
Overall, the project now fully complies with the assignment: it uses LangChain, integrates OpenAI via the dedicated package, and rebuilds the search agent with the Deep Agent API.