diff options
| author | CaptainJack2491 <jayrupnakawala@gmail.com> | 2025-11-16 19:16:26 +0000 |
|---|---|---|
| committer | CaptainJack2491 <jayrupnakawala@gmail.com> | 2025-11-16 19:16:26 +0000 |
| commit | 666825f6cdcde8f107bc474853b1e3e13ad49370 (patch) | |
| tree | a3d30e8b34778bd747bd7fafa0098666f5310212 /src/agents/02-sandbox/works.py | |
| parent | 0a24528267e7e67be5d62daefbd061a98670eb15 (diff) | |
reasoning works for both toolcall and response
Diffstat (limited to 'src/agents/02-sandbox/works.py')
| -rw-r--r-- | src/agents/02-sandbox/works.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/agents/02-sandbox/works.py b/src/agents/02-sandbox/works.py new file mode 100644 index 0000000..d40c3aa --- /dev/null +++ b/src/agents/02-sandbox/works.py @@ -0,0 +1,50 @@ +import json +from typing import List +from langchain_core.messages import SystemMessage, HumanMessage +from langchain_ollama import ChatOllama + +tool_def = { + "type": "function", + "function": { + "name": "validate_user", + "description": "Validate user using historical addresses.\\n\\n Args:\\n user_id (int): the user ID.\\n addresses (List[str]): Previous addresses as a list of strings.", + "parameters": { + "type": "object", + "required": ["user_id", "addresses"], + "properties": { + "addresses": {"type": "array", "items": {"type": "string"}, "description": ""}, + "user_id": {"type": "integer", "description": ""}, + }, + }, + }, +} + +system_prompt = f"""# Tools + +You may call one or more functions to assist with the user query. + +You are provided with function signatures within <tools></tools> XML tags: +<tools> +{json.dumps(tool_def)} +</tools> + +For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags: +<tool_call> +{{"name": "<function-name>", "arguments": "<args-json-object>"}} +</tool_call>""" + +llm = ChatOllama( + model="qwen3:1.7b", + temperature=0, +) + +messages = [ + SystemMessage(content=system_prompt), + HumanMessage(content="Could you validate user 123? They previously lived at 123 Fake St in Boston MA and 234 Pretend Boulevard in Houston TX.Think before you call any tools"), +] + +result = llm.invoke(messages) + +print("--- Full AIMessage Result ---") +print(result) + |
