{"id":20785978,"url":"https://github.com/thomassuedbroecker/agent_tools_langchain_chatwatsonx","last_synced_at":"2026-05-08T03:15:48.890Z","repository":{"id":253409023,"uuid":"843413336","full_name":"thomassuedbroecker/agent_tools_langchain_chatwatsonx","owner":"thomassuedbroecker","description":"The objective is to get a basic understanding of how to use the tools in AI agents by using the ChatWatsonx class.","archived":false,"fork":false,"pushed_at":"2024-08-26T16:28:04.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-28T20:53:51.294Z","etag":null,"topics":["agents","ai","function-calling","langchain","watsonx-ai"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomassuedbroecker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-16T13:10:44.000Z","updated_at":"2024-08-26T16:28:08.000Z","dependencies_parsed_at":"2024-08-26T19:26:26.014Z","dependency_job_id":null,"html_url":"https://github.com/thomassuedbroecker/agent_tools_langchain_chatwatsonx","commit_stats":null,"previous_names":["thomassuedbroecker/agent_tools_langchain_chatwatsonx"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thomassuedbroecker/agent_tools_langchain_chatwatsonx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fagent_tools_langchain_chatwatsonx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fagent_tools_langchain_chatwatsonx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fagent_tools_langchain_chatwatsonx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fagent_tools_langchain_chatwatsonx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomassuedbroecker","download_url":"https://codeload.github.com/thomassuedbroecker/agent_tools_langchain_chatwatsonx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fagent_tools_langchain_chatwatsonx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32764894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T02:36:36.067Z","status":"ssl_error","status_checked_at":"2026-05-08T02:36:07.210Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","ai","function-calling","langchain","watsonx-ai"],"created_at":"2024-11-17T14:49:54.118Z","updated_at":"2026-05-08T03:15:48.858Z","avatar_url":"https://github.com/thomassuedbroecker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Does it work to use WatsonxChat from langchain_ibm to implement an action that invokes functions?\n\nThis repository is an example using the langchain_ibm implementation for action and function calling with ChatWatsonx class.\n\nRelated blog post: [Does it work to use WatsonxChat from langchain_ibm to implement an action that invokes functions?](https://wp.me/paelj4-1Sc)\n\n## 0. Clone the repository\n\n```sh\ngit clone https://github.com/thomassuedbroecker/agent_tools_langchain_chatwatsonx.git\ncd agent_tools_langchain_chatwatsonx\n```\n\n## 1. Environment Setup\n\n### Step 1: Generate a virtual Python environment\n\n```sh\ncd code\npython3 -m venv --upgrade-deps venv\nsource venv/bin/activate\n```\n\n### Step 2: Install the needed libraries\n\n```sh \npython3 -m pip install -qU langchain-ibm\npython3 -m pip install -qU langchain\n```\n\n### Step 3: Generate a `.env` file for the needed environment variables\n\n```sh\ncat env_example_template \u003e .env\n```\n\nInsert the values for the two environment variables: \n\n* `WATSONX_PROJECT_ID=YOUR_WATSONX_PROJECT_ID`\n* `IBMCLOUD_APIKEY=YOUR_KEY`\n\nContent of the environment file.\n\n```sh\nexport IBMCLOUD_APIKEY=YOUR_KEY\nexport IBMCLOUD_URL=\"https://iam.cloud.ibm.com/identity/token\"\n\n# Watsonx\nexport WATSONX_URL=\"https://eu-de.ml.cloud.ibm.com\"\nexport WATSONX_VERSION=2023-05-29\nexport WATSONX_PROJECT_ID=YOUR_PROJECT_ID\n\nexport WATSONX_MIN_NEW_TOKENS=1\nexport WATSONX_MAX_NEW_TOKENS=300\nexport WATSONX_LLM_NAME=mistralai/mixtral-8x7b-instruct-v01\nexport WATSONX_INSTANCE_ID=YOUR_WATSONX_INSTANCE_ID\nexport WATSONX_USERNAME=\"exampe_user@exampl.net\"\n```\n\n## 2. Execution\n\n### Step 5: Run the example\n\n```sh\ncd code\nbash example_agent_invocation.sh\n```\n\n* Output of the invocation:\n\n```sg\n======== TOOL ONLY ========\n1. Verify the tool schema definition\n=============================\n1. Tool name:\ntoday_maximal_temperature\n2. Tool description:\nprovides the maximal temperature for today information for the given cities. \n     Args:\n                cities: The parameter cities is a list e.g. [ \"LA\", \"NY\"].\n3. Tool arguments:\n{'cities': {'title': 'Cities', 'type': 'array', 'items': {'type': 'string'}}}\n4. Tool arguments title:\nCities\n\n\n=============================\n\n\n2. Invoke the tool and print invocation result\n=============================\nResult:\n[{'city': 'Berlin', 'temperature_max': '29'}, {'city': 'NY', 'temperature_max': '28'}, {'city': 'Paris', 'temperature_max': '26'}]\n\n======== AGENT ONLY========\nSet LangChain Debug: False\n\n1. Load thhe environment variables\n{'project_id': 'YOUR_PROJECT', 'url': 'https://eu-de.ml.cloud.ibm.com', 'model_id': 'mistralai/mixtral-8x7b-instruct-v01', 'apikey': 'YOUR_IBMCLOUD_KEY'}\n\n\n2. Defined tools for langchain.tools.\n\n- The type to the tools:\n\u003cclass 'list'\u003e\n- The tools list:\n[StructuredTool(name='current_temperature', description='provides the current temperature information for given cities. \\n     Args:\\n                cities: The parameter cities is a list e.g. [\"LA\", \"NY\"].', args_schema=\u003cclass 'pydantic.v1.main.current_temperatureSchema'\u003e, func=\u003cfunction current_temperature at 0x168614180\u003e)]\n\n3. Define the model parameters\n{'decoding_method': 'greedy', 'max_new_tokens': 400, 'min_new_tokens': 1, 'temperature': 1.0}\n\n4. Create a ChatWatsonx instance for mistralai/mixtral-8x7b-instruct-v01, and not a WatsonxLLM, because to this instance a tool can't be bind.\n\n5. Define a prompt using a ChatPromptTemplate.\n\n-Prompt Template:\n\u003cclass 'langchain_core.prompts.chat.ChatPromptTemplate'\u003e\n\ninput_variables=['input'] optional_variables=['agent_scratchpad', 'chat_history'] input_types={'chat_history': typing.List[typing.Union[langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage]], 'agent_scratchpad': typing.List[typing.Union[langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage]]} partial_variables={'chat_history': [], 'agent_scratchpad': []} messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template=\"You are a weather expert. If the question is not about the weather, say: I don't know.\")), MessagesPlaceholder(variable_name='chat_history', optional=True), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], template='{input}')), MessagesPlaceholder(variable_name='agent_scratchpad', optional=True)]\n\n6. Create a tool calling agent based on parameters: the watsonx_chat_with_tools, the tool, and the prompt.\n\n7. Create an AgentExecutor.\n\n8. Execute the agent using the AgentExecutor by providing a question as input to invoke the model.\n\n\n\n\u003e Entering new AgentExecutor chain...\n\n\n```json\n{\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"current_temperature\",\n        \"arguments\": {\n            \"cities\": [\"LA\", \"NY\"]\n        }\n    }\n}\n```\n\n\u003c/endoftext\u003e\n\n\u003e Finished chain.\n\n\n\u003e Entering new AgentExecutor chain...\n\n\n```json\n{\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"current_temperature\",\n        \"arguments\": {\n            \"cities\": [\"Berlin\"]\n        }\n    }\n}\n```\n\u003c/endoftext\u003e\n\n\u003e Finished chain.\n\n\n\u003e Entering new AgentExecutor chain...\n\n\n```json\n{\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"Final Answer\",\n        \"arguments\": {\n            \"output\": \"I don't know.\"\n        }\n    }\n}\n\u003c/endoftext\u003e\n\n\u003e Finished chain.\n\n\n\u003e Entering new AgentExecutor chain...\n\n\n```json\n{\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"Final Answer\",\n        \"arguments\": {\n            \"output\": \"The term 'weather' refers to the state of the atmosphere at a particular place and time, with respect to temperature, humidity, cloudiness, wind, and atmospheric pressure.\"\n        }\n    }\n}\n```\n\u003c/endoftext\u003e\n\n\u003e Finished chain.\n9. Results\n\n|                 agent question                     |                  agent anwser                      |\n|----------------------------------------------------|----------------------------------------------------|\n|Which city is hotter today: LA or NY?_______________|function:current_temperature________________________|\n|What is the temperature today in Berlin?____________|function:current_temperature________________________|\n|How to win a soccer game?___________________________|function:Final Answer_______________________________|\n|What is the official definition of the term weather?|function:Final Answer_______________________________|\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassuedbroecker%2Fagent_tools_langchain_chatwatsonx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomassuedbroecker%2Fagent_tools_langchain_chatwatsonx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassuedbroecker%2Fagent_tools_langchain_chatwatsonx/lists"}