How to change an agent’s task while it’s still running:
A long analysis run can go on for tens of minutes. Somewhere in the middle, a new file shows up, or the review criteria change, and most systems give you one option, which is to start over.
Everything the run already finished gets discarded with it.
The reason is that the plan only exists inside the prompt. A deep research pipeline usually decides its steps up front and then executes them to completion, so there’s no object to edit while the run is live. Regenerating the whole thing is the only safe move.
The solution is to keep task state outside the conversation as an explicit structure, covering the plan, the steps that finished, the artifacts each one produced, and which steps depend on which.
Once dependencies are explicit, a new requirement doesn’t invalidate the run. It invalidates a subgraph.
The system checks the new input against completed steps, keeps the artifacts that are still valid, marks only the downstream dependents as stale, and replans that part. This is closer to an incremental rebuild than a fresh start.
The visual below explains this:
The same state object also keeps parallel work interruptible.
When subagents run branches concurrently and write results back into shared state as they finish, a change committed while branches are still running reaches the ones that haven’t started yet.
This implies that producing a correct answer and carrying a task through to a checkable result are different capabilities, and the second one is mostly a state management problem.
To see this in practice, Apodex is an AI lab working on exactly this, and Apodex 1.1 is their model for long analysis tasks.
A task there starts from actual files like spreadsheets, PDFs, and datasets. The model inspects and cleans the data, picks a method, writes and runs the code, repairs steps that fail, and returns figures and files.
The plan, the finished steps, the outputs, and the exceptions stay on a task board while it runs, which is where a mid-task change gets absorbed.
In their Deep Discover mode, the model decides whether to split the task at all, how many subagents to run, and when to merge what they return.
Before a key claim is shipped, a separate check runs it against the evidence and the code output. If a citation doesn’t match or a computed number conflicts with the reported one, it gets flagged, sent back, and the correction stays on record.
FrontierAgent is their open-source runtime for this, with a command-line TUI. One mode runs a single agent through the task in order, and the other puts a coordinator in front of parallel subagents. It starts with one command on macOS and Linux, and it doesn’t need Docker.
GitHub repo: github.com/ApodexAI/FrontierAgent (don’t forget to star it ⭐)
Apodex 1.1 mini is the open-weight 35B model, and it runs locally with FrontierAgent: huggingface.co/collections/apodex/apodex-11
The web workspace runs the full model, and new accounts get registration credits. Upload one of your own datasets and run a task end to end: apodex.ai
Both apodex-1.1 and apodex-1.1-mini are available on the API, and core model access is free for two weeks as a limited-time offer here: platform.apodex.ai
On a long trajectory, the only supervision is the final outcome, so a run that fails late gets no credit for the early work that was sound, and a run that succeeds gets no penalty for the weakly grounded steps along the way.
Their method, PIVOT-RL, locates the decision where the run went wrong, keeps the prefix that was working, restores the environment state, and builds a shorter continuation task from that point.
So you get to keep what’s still valid, redo only the rest, in training and at runtime.
The technical report on arXiv covers the method in full →
Thanks to Apodex for partnering today!
Implementing Siamese Network with Contrastive Learning
A few days back, we covered contrastive learning.
Today, let’s implement it.
On a side note, CLIP (Contrastive Language–Image Pretraining) is a model developed by OpenAI that creates a shared representation space for text and images.
Unlike traditional models that handle text or images in isolation, CLIP allows us to compare and reason about text and images together, which makes it a key component of multimodal systems like Retrieval-Augmented Generation (RAG).
A key element of this model is Contrastive learning (which is also reflected in its name).
We covered this in Part 5 of the RAG crash course here (open access) →
To recap, it is a popular self-supervised learning technique that teaches models to learn useful representations by comparing samples.
Here’s the overview:
Create a dataset of face pairs:
If a pair belongs to the same person, the true label will be 0.
If a pair belongs to different people, the true label will be 1.
After creating this data, define a network like this:
Pass both inputs through the same network to generate two embeddings.
If the true label is 0 (same person) → minimize the distance between the two embeddings.
If the true label is 1 (different person) → maximize the distance between the two embeddings.
Contrastive loss (defined below) helps us train such a model:
where:
yis the true label.Dis the distance between two embeddings.marginis a hyperparameter, typically greater than 1.
Next, let’s look at the implementation.
We start with some standard imports:
Next, we download/load the MNIST dataset:
Now, recall that to build a Siamese network, we have to create image pairs:
In some pairs, the two images will have the same true label.
In other pairs, the two images will have a different true label.
To do this, we define a SiameseDataset class that inherits from the Dataset class of PyTorch, and here, we implement this data creation logic:
Line 5: We obtain the current instance.
Line 7: We randomly decide whether this instance should be paired with the same class or not.
Lines 9-12: If
flag=1, continue to find an instance until we get an instance of the same class.Lines 14-17: If
flag=0, continue to find an instance until we get an instance of a different class.Line 23:
If the two labels are different, the true label for the pair will be 1.
If the two labels are the same, the true label for the pair will be 0.
After defining the class, we create the dataset objects below:
Next, we define the neural network:
The two input images are fed through the same network to generate an embedding (
outputAandoutputB).
Moving on, we define the contrastive loss:
Almost done!
Next, we define the dataloader, the model, the optimizer, and the loss function:
Finally, we train it:
And with that, we have successfully implemented a Siamese Network using PyTorch.
Results
Let’s look at some results using images in the test dataset:
We can generate a similarity score as follows:
Image pair #1: Similarity is high since both images depict the same digit:
Image pair #2: Similarity is low since both images depict different digits:
Image pair #3: Similarity is high since both images depict the same digit:
Image pair #4: Similarity is low since both images depict different digits:
It works as expected!
As mentioned above, CLIP (Contrastive Language–Image Pretraining) is a model developed by OpenAI that creates a shared representation space for text and images.
Unlike traditional models that handle text or images in isolation, CLIP allows us to compare and reason about text and images together, which makes it a key component of multimodal systems like Retrieval-Augmented Generation (RAG).
A key element of this model is Contrastive learning (which is also reflected in its name).
We covered this in Part 5 of the RAG crash course here (open access) →
Good day!
P.S. For those wanting to develop “Industry ML” expertise:
At the end of the day, all businesses care about impact. That’s it!
Can you reduce costs?
Drive revenue?
Can you scale ML models?
Predict trends before they happen?
We have discussed several other topics (with implementations) that align with such topics.
Here are some of them:
Learn everything about MCPs in this crash course with 9 parts →
Learn how to build Agentic systems in a crash course with 14 parts.
Learn how to build real-world RAG apps and evaluate and scale them in this crash course.
Learn sophisticated graph architectures and how to train them on graph data.
So many real-world NLP systems rely on pairwise context scoring. Learn scalable approaches here.
Learn how to run large models on small devices using Quantization techniques.
Learn how to generate prediction intervals or sets with strong statistical guarantees for increasing trust using Conformal Predictions.
Learn how to identify causal relationships and answer business questions using causal inference in this crash course.
Learn how to scale and implement ML model training in this practical guide.
Learn techniques to reliably test new models in production.
Learn how to build privacy-first ML systems using Federated Learning.
Learn 6 techniques with implementation to compress ML models.
All these resources will help you cultivate key skills that businesses and companies care about the most.


























Great 👍