Quick inference resource:
here
This model was trained using a combination of datasets under different open licenses.
Each dataset retains its original license, and use of those datasets is subject to their respective terms.
*All evaluations were conducted using greedy decoding (sampling parameter was set to false during HuggingFace inference).
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "quwsarohi/NanoAgent-135M"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
6
7def inference(messages, max_new_tokens=256, temperature=0.3, **kwargs):
8 if isinstance(message, list):
9 input_text = tokenizer.apply_chat_template(
10 messages, tokenize=False, add_generation_prompt=True
11 )
12 inputs = tokenizer.encode(input_text, return_tensors="pt").to(model.device)
13 outputs = model.generate(
14 inputs,
15 max_new_tokens=max_new_tokens,
16 do_sample=True,
17 temperature=temperature,
18 **kwargs
19 )
20 return tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
21
22messages = [{"role": "user", "content": "Hi! Do you have a name?"}]
23print(inference(messages))
1import json
2
3tools = [
4 {
5 "type": "function",
6 "function": {
7 "name": "web_search",
8 "description": "Performs a web search and returns formatted results.",
9 "parameters": {
10 "type": "object",
11 "properties": {
12 "query": {"type": "string", "description": "The search query."}
13 },
14 "required": ["query"],
15 },
16 }
17 }
18]
19
20TOOL_TEMPLATE = """You are a helpful AI assistant. You have a set of possible tools that you can execute to retrieve information or to perform specific actions. You can execute zero or more tools to answer user question.
21
22Here are the list of tools that you have access to:
23```json
24{tools}
25```
26
27Only execute tools from above. Follow the below JSON signature to execute tools:
28```json
29[{{"name": "tool_name", "arguments": {{"arg1": "val1", ...}}}}, ...]
30```
31"""
32
33messages = [
34 {"role": "system", "content": TOOL_TEMPLATE.format(tools=json.dumps(tools, indent=2))},
35 {"role": "user", "content": "What's the latest AI news?"},
36]
37response = inference(messages, max_new_tokens=512)
38print(response)
39
40# Output: ```json
41# [{"name": "web_search", "arguments": {"query": "latest AI news 2026"}}]
42# ```
1messages = [
2 {"role": "system", "content": TOOL_TEMPLATE.format(tools=json.dumps(tools, indent=2))},
3 {"role": "user", "content": "What's the latest AI news?"},
4 {"role": "assistant", "content": "```json\n"}
5]
6
7input_text = tokenizer.apply_chat_template(
8 messages,
9 tokenize=False,
10 add_generation_prompt=False,
11 continue_final_message=True
12)
13
14response = inference(input_text, max_new_tokens=512)
15print(response)
16
17# Output: [{"name": "web_search", "arguments": {"query": "latest AI news 2026"}}]
18# ```
19
This project (code, model weights, and training recipes) is licensed under the
Apache License 2.0.