In general, coalition agreements are structured so as to provide current benefits to both parties. For example, DUP (Democratic Unionist Party) could vote for Theresa May to be Prime Minister. In exchange, May appoints a DUP member as Home Secretary. If DUP then votes May out, their member would no longer be Home Secretary. If May fires their member, they can then issue a vote of no confidence, presumably with the support of the opposition, and effectively fire May.
That would be an example of how a coalition agreement could work. In the current actuality, they seem to be working at a lower level. DUP would rather May than Corbyn as Prime Minister. So they'll vote together on that issue. They may vote separately on other issues. They are not formally joining in a coalition.
To use a United States example, Bernie Sanders and Angus King caucus with the Democrats despite being elected as independents. This gives the Democrats two more votes for procedural issues like choosing the Majority Leader. In return, the Democrats give them committee assignments. The Democrats could kick them out of their committee assignments, but then they would be free to vote with the Republicans on Majority Leader.
Overall, they vote with the Democrats enough that it is to the Democrats' advantage to support them. And vice versa. But neither side has any legal obligation to support the other. That arrangement could collapse at any time. For example, Joe Lieberman was elected as an independent and caucused with the Democrats. But they ran a candidate against him and won.