Add examples of agent using Tavily server with key#25
Add examples of agent using Tavily server with key#25pamelafox merged 1 commit intoAzure-Samples:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds two new example files demonstrating how to use the Tavily MCP server with API key authentication, and makes consistency improvements to related agent files.
Key Changes:
- Adds LangChain and Agent Framework examples showing Tavily search integration with Bearer token authentication
- Improves code consistency by standardizing logger names and moving logger.setLevel() calls to be immediately after logger creation
- Simplifies code by removing unused imports and inlining constants
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
agents/langchainv1_tavily.py |
New LangChain example demonstrating Tavily MCP integration with API key authentication |
agents/agentframework_tavily.py |
New Agent Framework example demonstrating Tavily MCP integration with API key authentication |
agents/langchainv1_http.py |
Fixed logger name from "itinerario_lang" to "langchainv1_http" and moved setLevel() for consistency |
agents/agentframework_learn.py |
Removed unused imports, fixed logger name, moved setLevel(), and inlined constant for consistency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Load environment variables | ||
| load_dotenv(override=True) | ||
|
|
||
| api_host = os.getenv("API_HOST", "github") |
There was a problem hiding this comment.
The variable name api_host should follow Python naming conventions for constants that are module-level configuration values. Since this value is determined at module load time and used to configure the model, it should be named API_HOST (all uppercase) to be consistent with other similar files in the codebase (e.g., langchainv1_http.py line 27, agentframework_tavily.py line 22).
| model = ChatOpenAI( | ||
| model=os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT"), | ||
| base_url=os.environ["AZURE_OPENAI_ENDPOINT"] + "/openai/v1/", | ||
| api_key=token_provider, | ||
| ) | ||
| elif api_host == "github": | ||
| model = ChatOpenAI( | ||
| model=os.getenv("GITHUB_MODEL", "gpt-4o"), | ||
| base_url="https://models.inference.ai.azure.com", | ||
| api_key=SecretStr(os.environ["GITHUB_TOKEN"]), | ||
| ) | ||
| elif api_host == "ollama": | ||
| model = ChatOpenAI( | ||
| model=os.environ.get("OLLAMA_MODEL", "llama3.1"), | ||
| base_url=os.environ.get("OLLAMA_ENDPOINT", "http://localhost:11434/v1"), | ||
| api_key=SecretStr(os.environ.get("OLLAMA_API_KEY", "none")), | ||
| ) | ||
| else: | ||
| model = ChatOpenAI(model=os.getenv("OPENAI_MODEL", "gpt-4o-mini")) |
There was a problem hiding this comment.
The variable name model is inconsistent with similar files in the codebase. For example, langchainv1_http.py uses base_model for the same purpose. Using a more specific name like base_model or llm would improve code clarity and consistency across the codebase.
Similar to Learn, but demonstrates use of a key.
Also made some consistency tweaks with related agents.