VicroCode
Make Code Create Value
VicroCode is a lightweight online platform for publishing, running, sharing, and monetizing code projects. Launch HTML, Python, SQLite, AI agents, management tools, games, and more without server setup.
Please wait while VicroCode loads. You can also explore the AI programming guide
Loading...

AI MARKET GUIDE

Function Calling in Hosted Python: What the Market Expects You to Know and How to Build It

A practitioner walkthrough of building a tool-callable Python endpoint on VicroCode — covering Function Call patterns, in-platform model calls, SQLite state, and an HTML review page.

Job specs are a decent proxy for what the market actually values, and a recent AI quality-evaluation role circulating in the developer community makes the expectations explicit: candidates need hands-on experience with Function Call tool invocation, session-state flow, agent failure modes, and end-to-end log tracing across model, orchestration, retrieval, and tool layers. That's a fairly specific list. If you're a backend developer looking to get reps on exactly this stack, building and hosting a tool-callable Python endpoint is one of the tightest exercises you can do — and you can close the loop without leaving the browser using AI agent development and hosted Python execution.

This walkthrough covers the design decisions, the friction points, and the boundaries of what actually works.

What Does the Market Actually Want Developers to Build?

The job spec requirement is direct: understand Function Call tool invocation, session-state transitions, short and long memory (the spec names Engram-style memory modules specifically), multi-agent collaboration, and self-correction loops. It also asks for the ability to distinguish failures by layer — was it the model, the orchestration, the retrieval, or the tool?

That diagnostic skill only comes from having watched real failures in a real system.

Separately, the spec lists Python as the core execution requirement: write complex evaluation scripts, batch task scheduling, result parsing. That's the entry-level baseline, not a differentiator.

What this points to is a gap. Plenty of developers have used a hosted chat UI or called a model API in a notebook. Far fewer have wired a hosted Python backend to a model that can call functions defined in that same backend, persisted state across turns in a database, and surfaced the results in a shareable HTML page. That full loop is what the spec is probing for.

How Do You Structure a Tool-Callable Python Endpoint?

The design has three moving parts: the Python endpoint that defines and executes tools, the model that decides when to call them, and the state store that keeps the conversation coherent across turns.

Start with the Python side. Your endpoint receives a user message, constructs a `tools` array in the format the model expects (a JSON schema per function: name, description, parameters), and passes both to the model via the Model Center API. The model returns either a plain text response or a `tool_calls` block. If it returns tool calls, your code executes the named function locally, appends the result to the message history as a `tool` role message, and calls the model again. That second call is where the model synthesizes the tool result into a natural-language answer.

A minimal but realistic example: a `lookup_evaluation_score` tool that queries a local SQLite table of prior model evaluation runs. The function signature looks like this:

def lookup_evaluation_score(run_id: str, metric: str) -> dict:
    conn = sqlite3.connect("eval_runs.db")
    cur = conn.cursor()
    cur.execute(
        "SELECT value FROM scores WHERE run_id = ? AND metric = ?",
        (run_id, metric)
    )
    row = cur.fetchone()
    conn.close()
    return {"run_id": run_id, "metric": metric, "value": row[0] if row else None}

You register this in a tools schema, pass it to the model, and let the model decide when a user question warrants calling it. The model never touches your database directly — it emits a structured call, your Python executes it, and the result flows back.

Why Does SQLite Work Well Here, and Where Does It Break?

SQLite fits this pattern well for a few concrete reasons. There's no server process to manage, the database is a single file, and you can run Python online with SQLite in the standard library — no additional dependencies. For storing evaluation run results, session context, or tool call logs during development, it's the right size.

The limits are real, though. SQLite has no concurrent write support worth relying on. If your endpoint handles multiple simultaneous users writing to the same database file, you will see lock errors. For a single-developer evaluation tool or a low-traffic demo, this is fine. For anything with parallel users or background write processes, you'd need a different database — which is currently outside the confirmed VicroCode capability set.

The SQLite editor built into the platform is useful here: you can inspect your `eval_runs` table directly, verify that tool calls are writing what you expect, and manually seed test data without writing a migration script. That direct access cuts debugging time noticeably when you're chasing a mismatch between what the model said it called and what actually landed in the database.

How Do You Surface Results in a Shareable HTML Page?

Once the Python endpoint is running and writing evaluation results to SQLite, the natural next step is a lightweight review interface. An HTML web app hosted on the platform can call your Python API endpoint, fetch the stored results, and render them in a table or chart.

Keep this layer thin. The HTML page's job is display and navigation, not logic. It makes a `fetch()` call to your Python API, receives JSON, and renders it. Something like:

async function loadResults() {
  const res = await fetch('/api/eval-results');
  const data = await res.json();
  const tbody = document.querySelector('#results tbody');
  data.forEach(row => {
    const tr = document.createElement('tr');
    tr.innerHTML = `<td>${row.run_id}</td><td>${row.metric}</td><td>${row.value}</td>`;
    tbody.appendChild(tr);
  });
}

For the styling, use a neutral gray ramp and a single accent hue rather than default browser chrome. WCAG AA contrast for body text, tabular numerals for the score columns, and a sticky header if the table grows long. The goal is something you'd actually share with a colleague, not a demo that looks like it was styled in 2012.

Publishing and sharing that HTML app is a one-step operation on the platform, which matters if you're building this as a portfolio piece or handing it to a reviewer.

What Are the Real Failure Modes to Watch?

The job spec asks specifically for familiarity with agent failure modes and end-to-end tracing. Building this locally will surface a few of them quickly.

**Tool schema mismatch.** If your JSON schema says a parameter is required and the model omits it, the tool call will fail. The model doesn't always read schema constraints carefully, especially for parameters with names that seem self-explanatory. Add validation in the tool wrapper and return a structured error message rather than raising an exception — the model can recover from a structured error in the next turn, but an unhandled exception breaks the loop.

**Hallucinated tool calls.** Some models will call a tool with a `run_id` that doesn't exist in your database, particularly when the user's question is vague. The `lookup_evaluation_score` function above handles this by returning `None` rather than throwing. How you prompt the model to handle a `None` result determines whether the user gets a sensible response or a confabulated one.

**Infinite tool call loops.** If the model's second-pass response triggers another tool call instead of producing a final answer, and you don't set a recursion limit, you'll burn through tokens quickly. Cap the tool call depth at two or three turns and return a fallback response if the limit is hit. Log every iteration to your SQLite `tool_call_log` table so you can replay and diagnose the loop after the fact.

**State drift between turns.** If the message history grows and you're truncating it to stay within context limits, earlier tool results disappear from the model's view. The model may then call the same tool again or produce an answer inconsistent with earlier turns. This is the "session state flow" issue the job spec mentions. One mitigation: summarize resolved tool results into the system prompt rather than keeping the full raw history.

None of these are theoretical — they come up in the first few hours of real usage, which is exactly why the market is treating hands-on agent development experience as a hard requirement rather than a nice-to-have.

FAQ

Can VicroCode host both the Python backend and the HTML review page in the same project?

Yes — a Python-based API endpoint and a hosted HTML web app can coexist in the same project, with the HTML page making `fetch()` calls to the Python API. File management handles the shared assets, and both can be published and shared from the same project.

Does SQLite handle concurrent users writing evaluation results at the same time?

No, not reliably. SQLite serializes writes and will produce lock errors under concurrent write load. It works well for a single developer or low-traffic tool; a multi-user production system would require a different database, which falls outside the current confirmed platform capabilities.

What is the right way to log tool calls for post-hoc debugging?

Write every tool invocation — input arguments, return value, timestamp, and turn index — to a dedicated SQLite table immediately inside the tool wrapper function, before returning the result to the model. This gives you a complete replay trace without adding latency to the response path.

Further reading