Нема описа
Auto Commit 6205654270 Commit last changes: update react_agent пре 2 недеља
..
deploy Initialize repository and commit S1_skeleton changes пре 2 недеља
docs/graphs Initialize repository and commit S1_skeleton changes пре 2 недеља
src Commit last changes: update react_agent пре 2 недеља
tests Initialize repository and commit S1_skeleton changes пре 2 недеља
.env.example Initialize repository and commit S1_skeleton changes пре 2 недеља
.gitignore Initialize repository and commit S1_skeleton changes пре 2 недеља
.pre-commit-config.yaml Initialize repository and commit S1_skeleton changes пре 2 недеља
README.md Initialize repository and commit S1_skeleton changes пре 2 недеља
main.py Initialize repository and commit S1_skeleton changes пре 2 недеља
pyproject.toml Initialize repository and commit S1_skeleton changes пре 2 недеља
uv.lock Initialize repository and commit S1_skeleton changes пре 2 недеља

README.md

Agent Catalogue — Séance 1 · Squelette TP

Formation Agents IA · LangGraph · Projet fil rouge


Objectif

Implémenter un agent ReAct capable de répondre à des questions sur un catalogue produit, en utilisant des outils LangGraph.

Les tests vous disent si votre implémentation est correcte. Le formateur a la correction en cas de blocage.


Installation (5 min)

# 1. Installer les dépendances
uv sync --extra dev

# 2. Copier la configuration
cp .env.example .env
# Vérifier que MODEL_NAME correspond au modèle téléchargé

# 3. Démarrer Ollama
ollama serve &

# 4. Vérifier qu'Ollama répond
curl http://localhost:11434/v1/models

Ce que vous devez implémenter

Étape 1 — src/tools/catalogue.py

4 fonctions marquées TODO (dans l’ordre recommandé) :

Fonction Difficulté Tests
search_product() TestSearchProduct (5 tests)
calculate_price() ⭐⭐ TestCalculatePrice (7 tests)
list_products() ⭐⭐ TestListProducts (6 tests)
check_stock() ⭐ bonus TestCheckStock (5 tests)

Étape 2 — src/models/provider.py

1 fonction get_llm() : lire les variables d’env et retourner un ChatOpenAI.

Étape 3 — src/agents/react_agent.py

3 fonctions dans l’ordre :

Fonction Ce qu’elle fait
should_continue() Décide si l’agent utilise un outil ou s’arrête
agent_node() Appelle le LLM et retourne sa décision
build_agent() Assemble le graphe (noeuds + edges + compilation)

Lancer les tests

# Tous les tests unitaires (Ollama non requis)
uv run pytest tests/unit/ -v

# Un module à la fois
uv run pytest tests/unit/test_tools.py -v
uv run pytest tests/unit/test_agent.py -v

# Un test précis
uv run pytest tests/unit/test_tools.py::TestSearchProduct::test_found_by_partial_name -v

Tester l’agent manuellement

# Mode interactif (une fois react_agent.py implémenté)
uv run python main.py

# Question directe
uv run python main.py --ask "Quel est le prix d'une souris ?"

# Avec traces des outils appelés
uv run python main.py --verbose

# Visualiser le graphe LangGraph
uv run python main.py --visualize

Questions de test suggérées :

Quel est le prix d'un laptop pro ?
Je veux 3 souris avec une remise de 15%, combien ça coûte ?
Quels produits audio avez-vous ?
Puis-je commander 10 écrans 4K ?
Avez-vous des produits en rupture de stock ?

Vérification qualité

# Linting
uv run ruff check src/

# Typage strict
uv run mypy src/

Progression attendue

⬜ Étape 1a : search_product() → TestSearchProduct passe (5 tests)
⬜ Étape 1b : calculate_price() → TestCalculatePrice passe (7 tests)
⬜ Étape 1c : list_products() → TestListProducts passe (6 tests)
⬜ Étape 2  : get_llm() → provider.py implémenté
⬜ Étape 3a : should_continue() → TestShouldContinue passe (4 tests)
⬜ Étape 3b : agent_node() → TestAgentNode passe (4 tests)
⬜ Étape 3c : build_agent() → TestBuildAgent passe (3 tests)
⬜ Bonus     : check_stock() → TestCheckStock passe (5 tests)
⬜ Livrable  : premier commit poussé sur Git

Fichiers fournis (ne pas modifier)

Fichier Rôle
src/tools/catalogue.py CATALOGUE dict + squelettes
tests/unit/test_tools.py Spécification des outils
tests/unit/test_agent.py Spécification du graphe
main.py CLI interactif complet
pyproject.toml Dépendances + config
.env.example Variables d’environnement

Powered by TurnKey Linux.